diff options
author | Joey Hess <joey@kitenet.net> | 2011-12-09 12:23:45 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-12-09 12:23:45 -0400 |
commit | 3f5f28b48754bc91620a6354ca70afe4c61c9894 (patch) | |
tree | 6c71b52187f442ce619ffac7c672fc7f0b8f84ce /Command/Drop.hs | |
parent | d64132a43ae176e8a1353d5463c5387a93da9ad7 (diff) |
factor out a stopUnless
code melt for lunch
Diffstat (limited to 'Command/Drop.hs')
-rw-r--r-- | Command/Drop.hs | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/Command/Drop.hs b/Command/Drop.hs index ee3583869..0a4c9dfd6 100644 --- a/Command/Drop.hs +++ b/Command/Drop.hs @@ -37,13 +37,9 @@ start numcopies file (key, _) = autoCopies key (>) numcopies $ do else startRemote file numcopies key remote startLocal :: FilePath -> Maybe Int -> Key -> CommandStart -startLocal file numcopies key = do - present <- inAnnex key - if present - then do - showStart "drop" file - next $ performLocal key numcopies - else stop +startLocal file numcopies key = stopUnless (inAnnex key) $ do + showStart "drop" file + next $ performLocal key numcopies startRemote :: FilePath -> Maybe Int -> Key -> Remote.Remote Annex -> CommandStart startRemote file numcopies key remote = do @@ -55,12 +51,9 @@ performLocal key numcopies = lockContent key $ do (remotes, trusteduuids) <- Remote.keyPossibilitiesTrusted key untrusteduuids <- trustGet UnTrusted let tocheck = Remote.remotesWithoutUUID remotes (trusteduuids++untrusteduuids) - success <- canDropKey key numcopies trusteduuids tocheck [] - if success - then do - whenM (inAnnex key) $ removeAnnex key - next $ cleanupLocal key - else stop + stopUnless (canDropKey key numcopies trusteduuids tocheck []) $ do + whenM (inAnnex key) $ removeAnnex key + next $ cleanupLocal key performRemote :: Key -> Maybe Int -> Remote.Remote Annex -> CommandPerform performRemote key numcopies remote = lockContent key $ do @@ -75,12 +68,9 @@ performRemote key numcopies remote = lockContent key $ do untrusteduuids <- trustGet UnTrusted let tocheck = filter (/= remote) $ Remote.remotesWithoutUUID remotes (have++untrusteduuids) - success <- canDropKey key numcopies have tocheck [uuid] - if success - then do - ok <- Remote.removeKey remote key - next $ cleanupRemote key remote ok - else stop + stopUnless (canDropKey key numcopies have tocheck [uuid]) $ do + ok <- Remote.removeKey remote key + next $ cleanupRemote key remote ok where uuid = Remote.uuid remote |