summaryrefslogtreecommitdiffhomepage
path: root/Storage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-19 13:00:34 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-19 13:00:34 -0400
commit6261f7e58b764ae48293bee3b1863b518e9f0442 (patch)
treed9260d1beeced137e36c1ae1945c499d85e91608 /Storage
parentd3323ab8e9e39bcb0a6493d33efa265073920a7d (diff)
downloadkeysafe-6261f7e58b764ae48293bee3b1863b518e9f0442.tar.gz
rename shard -> share
This makes it clearer that it's not a chunk of data, but a Shamir share.
Diffstat (limited to 'Storage')
-rw-r--r--Storage/Local.hs64
-rw-r--r--Storage/Network.hs14
2 files changed, 39 insertions, 39 deletions
diff --git a/Storage/Local.hs b/Storage/Local.hs
index bbc3c41..510b8ef 100644
--- a/Storage/Local.hs
+++ b/Storage/Local.hs
@@ -27,11 +27,11 @@ newtype Section = Section String
localStorage :: String -> Storage
localStorage n = Storage
- { storeShard = store section
- , retrieveShard = retrieve section
- , obscureShards = obscure section
- , countShards = count section
- , moveShards = move section
+ { storeShare = store section
+ , retrieveShare = retrieve section
+ , obscureShares = obscure section
+ , countShares = count section
+ , moveShares = move section
}
where
section = Section n
@@ -39,11 +39,11 @@ localStorage n = Storage
uploadQueue :: Server -> Storage
uploadQueue s = localStorage ("uploadqueue" </> serverName s)
-store :: Section -> StorableObjectIdent -> Shard -> IO StoreResult
+store :: Section -> StorableObjectIdent -> Share -> IO StoreResult
store section i s = onError (StoreFailure . show) $ do
- dir <- shardDir section
+ dir <- shareDir section
createDirectoryIfMissing True dir
- let dest = dir </> shardFile i
+ let dest = dir </> shareFile i
exists <- doesFileExist dest
if exists
then return StoreAlreadyExists
@@ -57,14 +57,14 @@ store section i s = onError (StoreFailure . show) $ do
renameFile tmp dest
return StoreSuccess
-retrieve :: Section -> ShardNum -> StorableObjectIdent -> IO RetrieveResult
+retrieve :: Section -> ShareNum -> StorableObjectIdent -> IO RetrieveResult
retrieve section n i = onError (RetrieveFailure . show) $ do
- dir <- shardDir section
- fd <- openFd (dir </> shardFile i) ReadOnly Nothing defaultFileFlags
+ dir <- shareDir section
+ fd <- openFd (dir </> shareFile i) ReadOnly Nothing defaultFileFlags
h <- fdToHandle fd
b <- B.hGetContents h
b `deepseq` hClose h
- return $ RetrieveSuccess $ Shard n (StorableObject b)
+ return $ RetrieveSuccess $ Share n (StorableObject b)
-- | Set atime and mtime to epoch, to obscure access and modification
-- patterns.
@@ -73,37 +73,37 @@ retrieve section n i = onError (RetrieveFailure . show) $ do
-- times does at least set it to the current time, which makes all
-- currently stored files look alike.
--
--- Note that the contents of shards is never changed, so it's ok to set the
+-- Note that the contents of shares is never changed, so it's ok to set the
-- mtime to the epoch; backup programs won't be confused.
obscure :: Section -> IO ObscureResult
obscure section = onError (ObscureFailure . show) $ do
- dir <- shardDir section
- fs <- filter isShardFile <$> getDirectoryContents dir
+ dir <- shareDir section
+ fs <- filter isShareFile <$> getDirectoryContents dir
mapM_ (\f -> setFileTimes (dir </> f) 0 0) fs
return ObscureSuccess
count :: Section -> IO CountResult
count section = onError (CountFailure . show) $ do
- dir <- shardDir section
- CountResult . genericLength . filter isShardFile
+ dir <- shareDir section
+ CountResult . genericLength . filter isShareFile
<$> getDirectoryContents dir
move :: Section -> Storage -> IO ()
move section storage = do
- dir <- shardDir section
+ dir <- shareDir section
fs <- getDirectoryContents dir
- forM_ fs $ \f -> case fromShardFile f of
+ forM_ fs $ \f -> case fromShareFile f of
Nothing -> return ()
Just i -> do
- -- Use a dummy shard number of 0; it doesn't
+ -- Use a dummy share number of 0; it doesn't
-- matter because we're not going to be
- -- recombining the shard, just sending its contents
+ -- recombining the share, just sending its contents
-- on the the server.
r <- retrieve section 0 i
case r of
RetrieveFailure _ -> return ()
- RetrieveSuccess shard -> do
- s <- storeShard storage i shard
+ RetrieveSuccess share -> do
+ s <- storeShare storage i share
case s of
StoreFailure _ -> return ()
_ -> removeFile f
@@ -115,21 +115,21 @@ onError f a = do
Left e -> f e
Right r -> r
-shardDir :: Section -> IO FilePath
-shardDir (Section section) = do
+shareDir :: Section -> IO FilePath
+shareDir (Section section) = do
u <- getUserEntryForID =<< getEffectiveUserID
return $ homeDirectory u </> dotdir </> section
-shardFile :: StorableObjectIdent -> FilePath
-shardFile i = U8.toString (toByteString i) <> ext
+shareFile :: StorableObjectIdent -> FilePath
+shareFile i = U8.toString (toByteString i) <> ext
-fromShardFile :: FilePath -> Maybe StorableObjectIdent
-fromShardFile f
- | isShardFile f = fromByteString $ U8.fromString $ dropExtension f
+fromShareFile :: FilePath -> Maybe StorableObjectIdent
+fromShareFile f
+ | isShareFile f = fromByteString $ U8.fromString $ dropExtension f
| otherwise = Nothing
-isShardFile :: FilePath -> Bool
-isShardFile f = ext `isSuffixOf` f
+isShareFile :: FilePath -> Bool
+isShareFile f = ext `isSuffixOf` f
ext :: String
ext = ".keysafe"
diff --git a/Storage/Network.hs b/Storage/Network.hs
index 2b837dc..16ed97d 100644
--- a/Storage/Network.hs
+++ b/Storage/Network.hs
@@ -17,17 +17,17 @@ networkServers = return [] -- none yet
networkStorage :: Server -> Storage
networkStorage server = Storage
- { storeShard = store server
- , retrieveShard = retrieve server
- , obscureShards = obscure server
- , countShards = count server
- , moveShards = move server
+ { storeShare = store server
+ , retrieveShare = retrieve server
+ , obscureShares = obscure server
+ , countShares = count server
+ , moveShares = move server
}
-store :: Server -> StorableObjectIdent -> Shard -> IO StoreResult
+store :: Server -> StorableObjectIdent -> Share -> IO StoreResult
store _server _i _s = return $ StoreFailure "network storage not implemented yet"
-retrieve :: Server -> ShardNum -> StorableObjectIdent -> IO RetrieveResult
+retrieve :: Server -> ShareNum -> StorableObjectIdent -> IO RetrieveResult
retrieve _server _n _i = return $ RetrieveFailure "network storage not implemented yet"
-- | Servers should automatically obscure, so do nothing.