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.
This commit is contained in:
Joey Hess 2017-08-17 15:09:38 -04:00
parent 51801cff6a
commit 96c055eda2
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 31 additions and 4 deletions

View file

@ -69,6 +69,7 @@ module Annex.Locations (
hashDirMixed, hashDirMixed,
hashDirLower, hashDirLower,
preSanitizeKeyName, preSanitizeKeyName,
reSanitizeKeyName,
prop_isomorphic_fileKey prop_isomorphic_fileKey
) where ) where
@ -426,7 +427,10 @@ gitAnnexAssistantDefaultDir = "annex"
- same key. - same key.
-} -}
preSanitizeKeyName :: String -> String preSanitizeKeyName :: String -> String
preSanitizeKeyName = concatMap escape preSanitizeKeyName = preSanitizeKeyName' False
preSanitizeKeyName' :: Bool -> String -> String
preSanitizeKeyName' resanitize = concatMap escape
where where
escape c escape c
| isAsciiUpper c || isAsciiLower c || isDigit c = [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 -- , is safe and uncommon, so will be used to escape
-- other characters. By itself, it is escaped to -- other characters. By itself, it is escaped to
-- doubled form. -- doubled form.
| c == ',' = ",," | c == ',' = if not resanitize
then ",,"
else ","
| otherwise = ',' : show (ord c) | 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. {- Converts a key into a filename fragment without any directory.
- -
- Escape "/" in the key name, to keep a flat tree of files and avoid - Escape "/" in the key name, to keep a flat tree of files and avoid

View file

@ -22,8 +22,8 @@ backend = Backend
{ backendVariety = WORMKey { backendVariety = WORMKey
, getKey = keyValue , getKey = keyValue
, verifyKeyContent = Nothing , verifyKeyContent = Nothing
, canUpgradeKey = Nothing , canUpgradeKey = Just needsUpgrade
, fastMigrate = Nothing , fastMigrate = Just removeSpaces
, isStableKey = const True , isStableKey = const True
} }
@ -42,3 +42,17 @@ keyValue source = do
, keySize = Just sz , keySize = Just sz
, keyMtime = Just $ modificationTime stat , 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

View file

@ -21,6 +21,8 @@ git-annex (6.20170521) UNRELEASED; urgency=medium
* Prevent spaces from being embedded in the name of new WORM keys, * Prevent spaces from being embedded in the name of new WORM keys,
as that handing spaces in keys would complicate things like the as that handing spaces in keys would complicate things like the
external special remote protocol. external special remote protocol.
* migrate: WORM keys containing spaces will be migrated to not contain
spaces anymore.
-- Joey Hess <id@joeyh.name> Sat, 17 Jun 2017 13:02:24 -0400 -- Joey Hess <id@joeyh.name> Sat, 17 Jun 2017 13:02:24 -0400