summaryrefslogtreecommitdiffhomepage
path: root/Storage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-11 17:45:36 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-11 17:45:36 -0400
commit803cc369438f7850e6245ee2e4253dc480546bf4 (patch)
tree8dbbad57a352da185bc282d8dd8652786b4c6cf5 /Storage
parente450d7a2d1bdde57d01f027b2e5b8080095f1380 (diff)
downloadkeysafe-803cc369438f7850e6245ee2e4253dc480546bf4.tar.gz
catch IO exceptions
Diffstat (limited to 'Storage')
-rw-r--r--Storage/LocalFiles.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/Storage/LocalFiles.hs b/Storage/LocalFiles.hs
index a9496da..d339774 100644
--- a/Storage/LocalFiles.hs
+++ b/Storage/LocalFiles.hs
@@ -20,6 +20,7 @@ import System.Posix
import System.FilePath
import Raaz.Core.Encode
import Control.DeepSeq
+import Control.Exception
localFiles :: Storage
localFiles = Storage
@@ -28,7 +29,7 @@ localFiles = Storage
}
store :: StorableObjectIdent -> Shard -> IO StoreResult
-store i s = do
+store i s = onError (StoreFailure . show) $ do
dir <- shardDir
createDirectoryIfMissing True dir
fd <- openFd (dir </> shardFile i) WriteOnly (Just 0o666)
@@ -39,7 +40,7 @@ store i s = do
return StoreSuccess
retrieve :: ShardNum -> StorableObjectIdent -> IO RetrieveResult
-retrieve n i = do
+retrieve n i = onError (RetrieveFailure . show) $ do
dir <- shardDir
fd <- openFd (dir </> shardFile i) ReadOnly Nothing defaultFileFlags
h <- fdToHandle fd
@@ -47,6 +48,13 @@ retrieve n i = do
b `deepseq` hClose h
return $ RetrieveSuccess $ Shard n (StorableObject b)
+onError :: (IOException -> a) -> IO a -> IO a
+onError f a = do
+ v <- try a
+ return $ case v of
+ Left e -> f e
+ Right r -> r
+
shardDir :: IO FilePath
shardDir = do
u <- getUserEntryForID =<< getEffectiveUserID