diff options
Diffstat (limited to 'Storage')
-rw-r--r-- | Storage/LocalFiles.hs | 12 |
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" |