From 96c055eda2cf8c5f9be1c4bde611ea5839cbdae7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 17 Aug 2017 15:09:38 -0400 Subject: [PATCH] migrate: WORM keys containing spaces will be migrated to not contain spaces anymore To work around the problem that the external special remote protocol does not support keys containing spaces. This commit was sponsored by Denis Dzyubenko on Patreon. --- Annex/Locations.hs | 15 +++++++++++++-- Backend/WORM.hs | 18 ++++++++++++++++-- CHANGELOG | 2 ++ 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Annex/Locations.hs b/Annex/Locations.hs index e129200912..47768b9c10 100644 --- a/Annex/Locations.hs +++ b/Annex/Locations.hs @@ -69,6 +69,7 @@ module Annex.Locations ( hashDirMixed, hashDirLower, preSanitizeKeyName, + reSanitizeKeyName, prop_isomorphic_fileKey ) where @@ -426,7 +427,10 @@ gitAnnexAssistantDefaultDir = "annex" - same key. -} preSanitizeKeyName :: String -> String -preSanitizeKeyName = concatMap escape +preSanitizeKeyName = preSanitizeKeyName' False + +preSanitizeKeyName' :: Bool -> String -> String +preSanitizeKeyName' resanitize = concatMap escape where escape c | isAsciiUpper c || isAsciiLower c || isDigit c = [c] @@ -435,9 +439,16 @@ preSanitizeKeyName = concatMap escape -- , is safe and uncommon, so will be used to escape -- other characters. By itself, it is escaped to -- doubled form. - | c == ',' = ",," + | c == ',' = if not resanitize + then ",," + else "," | otherwise = ',' : show (ord c) +{- Converts a keyName that has been santizied with an old version of + - preSanitizeKeyName to be sanitized with the new version. -} +reSanitizeKeyName :: String -> String +reSanitizeKeyName = preSanitizeKeyName' True + {- Converts a key into a filename fragment without any directory. - - Escape "/" in the key name, to keep a flat tree of files and avoid diff --git a/Backend/WORM.hs b/Backend/WORM.hs index d7220a431c..678784fdf6 100644 --- a/Backend/WORM.hs +++ b/Backend/WORM.hs @@ -22,8 +22,8 @@ backend = Backend { backendVariety = WORMKey , getKey = keyValue , verifyKeyContent = Nothing - , canUpgradeKey = Nothing - , fastMigrate = Nothing + , canUpgradeKey = Just needsUpgrade + , fastMigrate = Just removeSpaces , isStableKey = const True } @@ -42,3 +42,17 @@ keyValue source = do , keySize = Just sz , keyMtime = Just $ modificationTime stat } + +{- Old WORM keys could contain spaces, and can be upgraded to remove them. -} +needsUpgrade :: Key -> Bool +needsUpgrade key = ' ' `elem` keyName key + +removeSpaces :: Key -> Backend -> AssociatedFile -> Maybe Key +removeSpaces oldkey newbackend _ + | migratable = Just $ oldkey + { keyName = reSanitizeKeyName (keyName oldkey) } + | otherwise = Nothing + where + migratable = oldvariety == newvariety + oldvariety = keyVariety oldkey + newvariety = backendVariety newbackend diff --git a/CHANGELOG b/CHANGELOG index 64a7c773d7..91a1e34880 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -21,6 +21,8 @@ git-annex (6.20170521) UNRELEASED; urgency=medium * Prevent spaces from being embedded in the name of new WORM keys, as that handing spaces in keys would complicate things like the external special remote protocol. + * migrate: WORM keys containing spaces will be migrated to not contain + spaces anymore. -- Joey Hess Sat, 17 Jun 2017 13:02:24 -0400