diff options
author | Joey Hess <joey@kitenet.net> | 2012-12-20 15:43:14 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-12-20 17:07:10 -0400 |
commit | 836c6429cc1db7212a5a391ea0a03326fc1edbd9 (patch) | |
tree | 9fc304c0acc2d62d24add6703db2119ae9aea98a /Backend/SHA.hs | |
parent | 0aedef26424c2e17a2cfc0bb24ec52bddc560bf0 (diff) |
handle sha*sum's leading \ in checksum with certian unsual filenames
* Bugfix: Remove leading \ from checksums output by sha*sum commands,
when the filename contains \ or a newline. Closes: #696384
* fsck: Still accept checksums with a leading \ as valid, now that
above bug is fixed.
* migrate: Remove leading \ in checksums
Diffstat (limited to 'Backend/SHA.hs')
-rw-r--r-- | Backend/SHA.hs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Backend/SHA.hs b/Backend/SHA.hs index ef0e92d20..1a278068e 100644 --- a/Backend/SHA.hs +++ b/Backend/SHA.hs @@ -34,6 +34,7 @@ genBackend size = Just $ Backend { name = shaName size , getKey = keyValue size , fsckKey = Just $ checkKeyChecksum size + , canUpgradeKey = Just $ needsUpgrade } genBackendE :: SHASize -> Maybe Backend @@ -61,6 +62,8 @@ shaN shasize file filesize = do parse command [] = bad command parse command (l:_) | null sha = bad command + -- sha is prefixed with \ when filename contains certian chars + | "\\" `isPrefixOf` sha = drop 1 sha | otherwise = sha where sha = fst $ separate (== ' ') l @@ -137,6 +140,17 @@ checkKeyChecksum size key file = do check <$> shaN size file filesize _ -> return True where + sha = keySha key check s - | s == dropExtensions (keyName key) = True + | s == sha = True + {- A bug caused checksums to be prefixed with \ in some + - cases; still accept these as legal now that the bug has been + - fixed. -} + | '\\' : s == sha = True | otherwise = False + +keySha :: Key -> String +keySha key = dropExtensions (keyName key) + +needsUpgrade :: Key -> Bool +needsUpgrade key = "\\" `isPrefixOf` keySha key |