diff options
author | Joey Hess <joey@kitenet.net> | 2012-03-16 01:59:07 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-03-16 01:59:07 -0400 |
commit | 184a69171d5d983ee2f08cce28011d235f44cc5c (patch) | |
tree | ff85fc620618b55c8cbed0d8c99212e73004f5b5 /Upgrade | |
parent | c0c9991c9f5322aef05f4c97d2c3f3bdc3101e46 (diff) |
removed another 10 lines via ifM
Diffstat (limited to 'Upgrade')
-rw-r--r-- | Upgrade/V0.hs | 13 | ||||
-rw-r--r-- | Upgrade/V1.hs | 56 |
2 files changed, 34 insertions, 35 deletions
diff --git a/Upgrade/V0.hs b/Upgrade/V0.hs index c439c7caa..8f3af337e 100644 --- a/Upgrade/V0.hs +++ b/Upgrade/V0.hs @@ -35,14 +35,11 @@ lookupFile0 :: FilePath -> Annex (Maybe (Key, Backend)) lookupFile0 = Upgrade.V1.lookupFile1 getKeysPresent0 :: FilePath -> Annex [Key] -getKeysPresent0 dir = do - exists <- liftIO $ doesDirectoryExist dir - if not exists - then return [] - else do - contents <- liftIO $ getDirectoryContents dir - files <- liftIO $ filterM present contents - return $ map fileKey0 files +getKeysPresent0 dir = ifM (liftIO $ doesDirectoryExist dir) + ( liftIO $ map fileKey0 + <$> (filterM present =<< getDirectoryContents dir) + , return [] + ) where present d = do result <- tryIO $ diff --git a/Upgrade/V1.hs b/Upgrade/V1.hs index ca2bff661..62e3b3b31 100644 --- a/Upgrade/V1.hs +++ b/Upgrade/V1.hs @@ -50,18 +50,18 @@ upgrade :: Annex Bool upgrade = do showAction "v1 to v2" - bare <- fromRepo Git.repoIsLocalBare - if bare - then do + ifM (fromRepo Git.repoIsLocalBare) + ( do moveContent setVersion - else do + , do moveContent updateSymlinks moveLocationLogs Annex.Queue.flush True setVersion + ) Upgrade.V2.upgrade @@ -104,12 +104,11 @@ moveLocationLogs = do where oldlocationlogs = do dir <- fromRepo Upgrade.V2.gitStateDir - exists <- liftIO $ doesDirectoryExist dir - if exists - then do - contents <- liftIO $ getDirectoryContents dir - return $ mapMaybe oldlog2key contents - else return [] + ifM (liftIO $ doesDirectoryExist dir) + ( mapMaybe oldlog2key + <$> (liftIO $ getDirectoryContents dir) + , return [] + ) move (l, k) = do dest <- fromRepo $ logFile2 k dir <- fromRepo Upgrade.V2.gitStateDir @@ -127,14 +126,13 @@ moveLocationLogs = do Annex.Queue.add "rm" [Param "--quiet", Param "-f", Param "--"] [f] oldlog2key :: FilePath -> Maybe (FilePath, Key) -oldlog2key l = - let len = length l - 4 in - if drop len l == ".log" - then let k = readKey1 (take len l) in - if null (keyName k) || null (keyBackendName k) - then Nothing - else Just (l, k) - else Nothing +oldlog2key l + | drop len l == ".log" && sane = Just (l, k) + | otherwise = Nothing + where + len = length l - 4 + k = readKey1 (take len l) + sane = (not . null $ keyName k) && (not . null $ keyBackendName k) -- WORM backend keys: "WORM:mtime:size:filename" -- all the rest: "backend:key" @@ -143,10 +141,14 @@ oldlog2key l = -- v2 and v1; that infelicity is worked around by treating the value -- as the v2 key that it is. readKey1 :: String -> Key -readKey1 v = - if mixup - then fromJust $ readKey $ join ":" $ Prelude.tail bits - else Key { keyName = n , keyBackendName = b, keySize = s, keyMtime = t } +readKey1 v + | mixup = fromJust $ readKey $ join ":" $ Prelude.tail bits + | otherwise = Key + { keyName = n + , keyBackendName = b + , keySize = s + , keyMtime = t + } where bits = split ":" v b = Prelude.head bits @@ -205,14 +207,14 @@ lookupFile1 file = do getKeyFilesPresent1 :: Annex [FilePath] getKeyFilesPresent1 = getKeyFilesPresent1' =<< fromRepo gitAnnexObjectDir getKeyFilesPresent1' :: FilePath -> Annex [FilePath] -getKeyFilesPresent1' dir = do - exists <- liftIO $ doesDirectoryExist dir - if not exists - then return [] - else do +getKeyFilesPresent1' dir = + ifM (liftIO $ doesDirectoryExist dir) + ( do dirs <- liftIO $ getDirectoryContents dir let files = map (\d -> dir ++ "/" ++ d ++ "/" ++ takeFileName d) dirs liftIO $ filterM present files + , return [] + ) where present f = do result <- tryIO $ getFileStatus f |