summaryrefslogtreecommitdiffhomepage
path: root/Storage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-11 20:51:49 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-11 20:51:49 -0400
commit73d1b3d2dfb0f225132ab31a701e6378422e2a37 (patch)
tree96f98e948fa2f872539553b8e137d02b6efff29c /Storage
parenta3834e558cf6ae04826b44e65a02ee22286f7952 (diff)
downloadkeysafe-73d1b3d2dfb0f225132ab31a701e6378422e2a37.tar.gz
add shardCount
Diffstat (limited to 'Storage')
-rw-r--r--Storage/LocalFiles.hs12
1 files changed, 11 insertions, 1 deletions
diff --git a/Storage/LocalFiles.hs b/Storage/LocalFiles.hs
index b81ecbe..fd77ba1 100644
--- a/Storage/LocalFiles.hs
+++ b/Storage/LocalFiles.hs
@@ -28,6 +28,7 @@ localFiles = Storage
{ storeShard = store
, retrieveShard = retrieve
, obscureShards = obscure
+ , countShards = count
}
store :: StorableObjectIdent -> Shard -> IO StoreResult
@@ -65,10 +66,16 @@ retrieve n i = onError (RetrieveFailure . show) $ do
obscure :: IO ObscureResult
obscure = onError (ObscureFailure . show) $ do
dir <- shardDir
- fs <- filter (ext `isSuffixOf`) <$> getDirectoryContents dir
+ fs <- filter isShardFile <$> getDirectoryContents dir
mapM_ (\f -> setFileTimes (dir </> f) 0 0) fs
return ObscureSuccess
+count :: IO CountResult
+count = onError (CountFailure . show) $ do
+ dir <- shardDir
+ CountResult . genericLength . filter isShardFile
+ <$> getDirectoryContents dir
+
onError :: (IOException -> a) -> IO a -> IO a
onError f a = do
v <- try a
@@ -87,5 +94,8 @@ shardFile i = U8.toString (toByteString i) <> ext
ext :: String
ext = ".keysafe"
+isShardFile :: FilePath -> Bool
+isShardFile f = ext `isSuffixOf` f
+
dotdir :: FilePath
dotdir = ".keysafe" </> "objects"