summaryrefslogtreecommitdiffhomepage
path: root/Storage/LocalFiles.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Storage/LocalFiles.hs')
-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