summaryrefslogtreecommitdiff
path: root/Backend
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-12-20 17:16:55 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-12-20 17:16:55 -0400
commit4c0c55360574ed20b63bf3a51d16f95240b316b5 (patch)
tree74ad7ec4ca4682721a3f6324e2c87833da06ae75 /Backend
parent836c6429cc1db7212a5a391ea0a03326fc1edbd9 (diff)
SHA*E backends: Exclude non-alphanumeric characters from extensions.
* SHA*E backends: Exclude non-alphanumeric characters from extensions. * migrate: Remove leading \ in SHA* checksums, and non-alphanumerics from extensions of SHA*E keys.
Diffstat (limited to 'Backend')
-rw-r--r--Backend/SHA.hs18
1 files changed, 13 insertions, 5 deletions
diff --git a/Backend/SHA.hs b/Backend/SHA.hs
index 1a278068e..34faa4922 100644
--- a/Backend/SHA.hs
+++ b/Backend/SHA.hs
@@ -17,6 +17,7 @@ import qualified Build.SysConfig as SysConfig
import Data.Digest.Pure.SHA
import qualified Data.ByteString.Lazy as L
import System.Process
+import Data.Char
type SHASize = Int
@@ -124,10 +125,8 @@ selectExtension f
where
es = filter (not . null) $ reverse $
take 2 $ takeWhile shortenough $
- reverse $ split "." $ takeExtensions f
- shortenough e
- | '\n' `elem` e = False -- newline in extension?!
- | otherwise = length e <= 4 -- long enough for "jpeg"
+ reverse $ split "." $ filter validExtension $ takeExtensions f
+ shortenough e = length e <= 4 -- long enough for "jpeg"
{- A key's checksum is checked during fsck. -}
checkKeyChecksum :: SHASize -> Key -> FilePath -> Annex Bool
@@ -152,5 +151,14 @@ checkKeyChecksum size key file = do
keySha :: Key -> String
keySha key = dropExtensions (keyName key)
+validExtension :: Char -> Bool
+validExtension c
+ | isAlphaNum c = True
+ | c == '.' = True
+ | otherwise = False
+
+{- Upgrade keys that have the \ prefix on their sha due to a bug, or
+ - that contain non-alphanumeric characters in their extension. -}
needsUpgrade :: Key -> Bool
-needsUpgrade key = "\\" `isPrefixOf` keySha key
+needsUpgrade key = "\\" `isPrefixOf` keySha key ||
+ any (not . validExtension) (takeExtensions $ keyName key)