rename key2file and file2key
What these generate is not really suitable to be used as a filename, which is why keyFile and fileKey further escape it. These are just serializing Keys. Also removed a quickcheck test that was very unlikely to test anything useful, since it relied on random chance creating something that looks like a serialized key. The other test is sufficient for testing what that was intended to test anyway.
This commit is contained in:
parent
ff0a2bee2d
commit
d3ab5e626b
40 changed files with 97 additions and 108 deletions
|
@ -65,14 +65,14 @@ hashDirs (HashLevels 1) sz s = addTrailingPathSeparator $ take sz s
|
|||
hashDirs _ sz s = addTrailingPathSeparator $ take sz s </> drop sz s
|
||||
|
||||
hashDirLower :: HashLevels -> Hasher
|
||||
hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $ key2file' $ nonChunkKey k
|
||||
hashDirLower n k = hashDirs n 3 $ take 6 $ show $ md5 $ serializeKey' $ nonChunkKey k
|
||||
|
||||
{- This was originally using Data.Hash.MD5 from MissingH. This new version
|
||||
- is faster, but ugly as it has to replicate the 4 Word32's that produced. -}
|
||||
hashDirMixed :: HashLevels -> Hasher
|
||||
hashDirMixed n k = hashDirs n 2 $ take 4 $ concatMap display_32bits_as_dir $
|
||||
encodeWord32 $ map fromIntegral $ Data.ByteArray.unpack $
|
||||
Utility.Hash.md5 $ key2file' $ nonChunkKey k
|
||||
Utility.Hash.md5 $ serializeKey' $ nonChunkKey k
|
||||
where
|
||||
encodeWord32 (b1:b2:b3:b4:rest) =
|
||||
(shiftL b4 24 .|. shiftL b3 16 .|. shiftL b2 8 .|. b1)
|
||||
|
|
|
@ -115,7 +115,7 @@ handleDropsFrom locs rs reason fromhere key afile preverified runner = do
|
|||
liftIO $ debugM "drop" $ unwords
|
||||
[ "dropped"
|
||||
, case afile of
|
||||
AssociatedFile Nothing -> key2file key
|
||||
AssociatedFile Nothing -> serializeKey key
|
||||
AssociatedFile (Just af) -> af
|
||||
, "(from " ++ maybe "here" show u ++ ")"
|
||||
, "(copies now " ++ show (fromNumCopies have - 1) ++ ")"
|
||||
|
|
|
@ -506,7 +506,7 @@ reSanitizeKeyName = preSanitizeKeyName' True
|
|||
- can cause existing objects to get lost.
|
||||
-}
|
||||
keyFile :: Key -> FilePath
|
||||
keyFile = concatMap esc . key2file
|
||||
keyFile = concatMap esc . serializeKey
|
||||
where
|
||||
esc '&' = "&a"
|
||||
esc '%' = "&s"
|
||||
|
@ -517,7 +517,7 @@ keyFile = concatMap esc . key2file
|
|||
{- Reverses keyFile, converting a filename fragment (ie, the basename of
|
||||
- the symlink target) into a key. -}
|
||||
fileKey :: FilePath -> Maybe Key
|
||||
fileKey = file2key . unesc []
|
||||
fileKey = deserializeKey . unesc []
|
||||
where
|
||||
unesc r [] = reverse r
|
||||
unesc r ('%':cs) = unesc ('/':r) cs
|
||||
|
|
|
@ -34,8 +34,8 @@ mkVariant file variant = takeDirectory file
|
|||
-}
|
||||
variantFile :: FilePath -> Key -> FilePath
|
||||
variantFile file key
|
||||
| doubleconflict = mkVariant file (key2file key)
|
||||
| otherwise = mkVariant file (shortHash $ key2file key)
|
||||
| doubleconflict = mkVariant file (serializeKey key)
|
||||
| otherwise = mkVariant file (shortHash $ serializeKey key)
|
||||
where
|
||||
doubleconflict = variantMarker `isInfixOf` file
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue