summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Storage.hs6
-rw-r--r--Storage/LocalFiles.hs12
2 files changed, 16 insertions, 2 deletions
diff --git a/Storage.hs b/Storage.hs
index fc9e9ed..cb0e323 100644
--- a/Storage.hs
+++ b/Storage.hs
@@ -13,7 +13,8 @@ data Storage = Storage
, obscureShards :: IO ObscureResult
-- ^ run after making some calls to storeShard/retrieveShard,
-- to avoid correlation attacks
- }
+ , countShards :: IO CountResult
+ } -- Note that there is no interface to enumerate shards.
data StoreResult = StoreSuccess | StoreFailure String
deriving (Show)
@@ -22,3 +23,6 @@ data RetrieveResult = RetrieveSuccess Shard | RetrieveFailure String
data ObscureResult = ObscureSuccess | ObscureFailure String
deriving (Show)
+
+data CountResult = CountResult Integer | CountFailure String
+ deriving (Show)
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"