refactor
This commit is contained in:
parent
9606409b9d
commit
89fab6c7b8
2 changed files with 16 additions and 14 deletions
|
@ -82,14 +82,14 @@ store d k = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
let src = gitAnnexLocation g k
|
let src = gitAnnexLocation g k
|
||||||
let dest = dirKey d k
|
let dest = dirKey d k
|
||||||
liftIO $ catch (storeHelper dest $ copyFile src dest) (const $ return False)
|
liftIO $ catchBool $ storeHelper dest $ copyFile src dest
|
||||||
|
|
||||||
storeEncrypted :: FilePath -> (Cipher, Key) -> Key -> Annex Bool
|
storeEncrypted :: FilePath -> (Cipher, Key) -> Key -> Annex Bool
|
||||||
storeEncrypted d (cipher, enck) k = do
|
storeEncrypted d (cipher, enck) k = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
let src = gitAnnexLocation g k
|
let src = gitAnnexLocation g k
|
||||||
let dest = dirKey d enck
|
let dest = dirKey d enck
|
||||||
liftIO $ catch (storeHelper dest $ encrypt src dest) (const $ return False)
|
liftIO $ catchBool $ storeHelper dest $ encrypt src dest
|
||||||
where
|
where
|
||||||
encrypt src dest = do
|
encrypt src dest = do
|
||||||
content <- L.readFile src
|
content <- L.readFile src
|
||||||
|
@ -112,23 +112,20 @@ retrieve d k f = liftIO $ copyFile (dirKey d k) f
|
||||||
|
|
||||||
retrieveEncrypted :: FilePath -> (Cipher, Key) -> FilePath -> Annex Bool
|
retrieveEncrypted :: FilePath -> (Cipher, Key) -> FilePath -> Annex Bool
|
||||||
retrieveEncrypted d (cipher, enck) f =
|
retrieveEncrypted d (cipher, enck) f =
|
||||||
liftIO $ catch decrypt (const $ return False)
|
liftIO $ catchBool $ do
|
||||||
where
|
content <- L.readFile (dirKey d enck)
|
||||||
decrypt = do
|
withDecryptedContent cipher content $ L.writeFile f
|
||||||
content <- L.readFile (dirKey d enck)
|
return True
|
||||||
withDecryptedContent cipher content $ L.writeFile f
|
|
||||||
return True
|
|
||||||
|
|
||||||
remove :: FilePath -> Key -> Annex Bool
|
remove :: FilePath -> Key -> Annex Bool
|
||||||
remove d k = liftIO $ catch del (const $ return False)
|
remove d k = liftIO $ catchBool $ do
|
||||||
|
allowWrite dir
|
||||||
|
removeFile file
|
||||||
|
removeDirectory dir
|
||||||
|
return True
|
||||||
where
|
where
|
||||||
file = dirKey d k
|
file = dirKey d k
|
||||||
dir = parentDir file
|
dir = parentDir file
|
||||||
del = do
|
|
||||||
allowWrite dir
|
|
||||||
removeFile file
|
|
||||||
removeDirectory dir
|
|
||||||
return True
|
|
||||||
|
|
||||||
checkPresent :: FilePath -> Key -> Annex (Either IOException Bool)
|
checkPresent :: FilePath -> Key -> Annex (Either IOException Bool)
|
||||||
checkPresent d k = liftIO $ try $ doesFileExist (dirKey d k)
|
checkPresent d k = liftIO $ try $ doesFileExist (dirKey d k)
|
||||||
|
|
|
@ -24,6 +24,7 @@ module Utility (
|
||||||
dirContains,
|
dirContains,
|
||||||
dirContents,
|
dirContents,
|
||||||
myHomeDir,
|
myHomeDir,
|
||||||
|
catchBool,
|
||||||
|
|
||||||
prop_idempotent_shellEscape,
|
prop_idempotent_shellEscape,
|
||||||
prop_idempotent_shellEscape_multiword,
|
prop_idempotent_shellEscape_multiword,
|
||||||
|
@ -256,3 +257,7 @@ myHomeDir = do
|
||||||
uid <- getEffectiveUserID
|
uid <- getEffectiveUserID
|
||||||
u <- getUserEntryForID uid
|
u <- getUserEntryForID uid
|
||||||
return $ homeDirectory u
|
return $ homeDirectory u
|
||||||
|
|
||||||
|
{- Catches IO errors and returns a Bool -}
|
||||||
|
catchBool :: IO Bool -> IO Bool
|
||||||
|
catchBool = flip catch (const $ return False)
|
||||||
|
|
Loading…
Reference in a new issue