From: pho Date: Mon, 7 Jan 2008 14:36:11 +0000 (+0900) Subject: implemented page moving X-Git-Url: https://git.cielonegro.org/gitweb.cgi?a=commitdiff_plain;h=5311fe068286b30d52063ef97cc00f09f65a47f1;p=Rakka.git implemented page moving darcs-hash:20080107143611-62b54-fb97a031f4320e41bc1268d21b492693ce4b558e.gz --- diff --git a/Rakka/Page.hs b/Rakka/Page.hs index 9883b57..c1d7211 100644 --- a/Rakka/Page.hs +++ b/Rakka/Page.hs @@ -376,9 +376,9 @@ parseEntity parseUpdateInfo :: (ArrowXml a, ArrowChoice a) => a XmlTree UpdateInfo parseUpdateInfo = proc tree - -> do uInfo <- getXPathTreesInDoc "/*/updateInfo" -< tree + -> do uInfo <- getXPathTreesInDoc "/page/updateInfo" -< tree oldRev <- (getAttrValue0 "oldRevision" >>> arr read) -< uInfo - oldName <- maybeA (getXPathTrees "/move/@from/text()" >>> getText) -< uInfo + oldName <- maybeA (getXPathTrees "/updateInfo/move/@from/text()" >>> getText) -< uInfo returnA -< UpdateInfo { uiOldRevision = oldRev , uiOldName = oldName diff --git a/Rakka/Storage/Repos.hs b/Rakka/Storage/Repos.hs index 576e5b7..8e717ed 100644 --- a/Rakka/Storage/Repos.hs +++ b/Rakka/Storage/Repos.hs @@ -181,7 +181,7 @@ putPageIntoRepository repos page (Just "Automatic commit by Rakka for page update") $ do case uiOldName ui of Nothing -> return () - Just oldName -> renamePage oldName name + Just oldName -> renamePage (uiOldRevision ui) oldName name updatePage name Nothing -> do fs <- getRepositoryFS repos @@ -196,9 +196,14 @@ putPageIntoRepository repos page Left _ -> return Conflict Right _ -> return Created where - renamePage :: PageName -> PageName -> Txn () - renamePage oldName newName - = fail "FIXME: renamePage: not implemented yet" + renamePage :: RevNum -> PageName -> PageName -> Txn () + renamePage oldRev oldName newName + = do let oldPath = mkPagePath oldName + newPath = mkPagePath newName + createParentDirectories newPath + copyEntry oldRev oldPath newPath + deleteEntry oldPath + deleteEmptyParentDirectories oldPath createPage :: PageName -> Txn () createPage name @@ -206,16 +211,6 @@ putPageIntoRepository repos page createParentDirectories path makeFile path - createParentDirectories :: FilePath -> Txn () - createParentDirectories path - = do let parentPath = takeDirectory path - kind <- checkPath parentPath - case kind of - NoNode -> do createParentDirectories parentPath - makeDirectory parentPath - FileNode -> fail ("createParentDirectories: already exists a file: " ++ parentPath) - DirNode -> return () - updatePage :: PageName -> Txn () updatePage name | isRedirect page = updatePageRedirect name @@ -260,6 +255,17 @@ putPageIntoRepository repos page encodeFlag False = Nothing +createParentDirectories :: FilePath -> Txn () +createParentDirectories path + = do let parentPath = takeDirectory path + kind <- checkPath parentPath + case kind of + NoNode -> do createParentDirectories parentPath + makeDirectory parentPath + FileNode -> fail ("createParentDirectories: already exists a file: " ++ parentPath) + DirNode -> return () + + deletePageFromRepository :: Repository -> PageName -> IO StatusCode deletePageFromRepository repos name = filterSvnError $ @@ -277,14 +283,15 @@ deletePageFromRepository repos name return NoContent else return NotFound - where - deleteEmptyParentDirectories :: FilePath -> Txn () - deleteEmptyParentDirectories path - = do let parentPath = takeDirectory path - contents <- getDirEntries parentPath - when (null contents) - $ do deleteEntry parentPath - deleteEmptyParentDirectories parentPath + + +deleteEmptyParentDirectories :: FilePath -> Txn () +deleteEmptyParentDirectories path + = do let parentPath = takeDirectory path + contents <- getDirEntries parentPath + when (null contents) + $ do deleteEntry parentPath + deleteEmptyParentDirectories parentPath filterSvnError :: IO a -> IO a