From 73d1b3d2dfb0f225132ab31a701e6378422e2a37 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 11 Aug 2016 20:51:49 -0400 Subject: add shardCount --- Storage/LocalFiles.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Storage') 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" -- cgit v1.2.3