fix migration bug and make fsck warn
* migrate: Fix bug in migration between eg SHA256 and SHA256E, that caused the extension to be included in SHA256 keys, and omitted from SHA256E keys. (Bug introduced in version 6.20170214) * migrate: Check for above bug when migrating from SHA256 to SHA256 (and same for SHA1 to SHA1 etc), and remove the extension that should not be in the SHA256 key. * fsck: Detect and warn when keys need an upgrade, either to fix up from the above migrate bug, or to add missing size information (a long ago transition), or because of a few other past key related bugs. This commit was sponsored by Henrik Riomar on Patreon.
This commit is contained in:
parent
deff25549a
commit
2da2ae0919
5 changed files with 86 additions and 6 deletions
|
@ -150,26 +150,41 @@ validInExtension c
|
|||
| 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. -}
|
||||
{- Upgrade keys that have the \ prefix on their hash due to a bug, or
|
||||
- that contain non-alphanumeric characters in their extension.
|
||||
-
|
||||
- Also, for a while migrate from eg SHA256E to SHA256 resulted in a SHA256
|
||||
- key that contained an extension inside its keyName. Upgrade those
|
||||
- keys, removing the extension.
|
||||
-}
|
||||
needsUpgrade :: Key -> Bool
|
||||
needsUpgrade key = "\\" `isPrefixOf` keyHash key ||
|
||||
any (not . validInExtension) (takeExtensions $ keyName key)
|
||||
needsUpgrade key = or
|
||||
[ "\\" `isPrefixOf` keyHash key
|
||||
, any (not . validInExtension) (takeExtensions $ keyName key)
|
||||
, not (hasExt (keyVariety key)) && keyHash key /= keyName key
|
||||
]
|
||||
|
||||
trivialMigrate :: Key -> Backend -> AssociatedFile -> Maybe Key
|
||||
trivialMigrate oldkey newbackend afile
|
||||
{- Fast migration from hashE to hash backend. -}
|
||||
| migratable && hasExt newvariety = Just $ oldkey
|
||||
| migratable && hasExt oldvariety = Just $ oldkey
|
||||
{ keyName = keyHash oldkey
|
||||
, keyVariety = newvariety
|
||||
}
|
||||
{- Fast migration from hash to hashE backend. -}
|
||||
| migratable && hasExt oldvariety = case afile of
|
||||
| migratable && hasExt newvariety = case afile of
|
||||
AssociatedFile Nothing -> Nothing
|
||||
AssociatedFile (Just file) -> Just $ oldkey
|
||||
{ keyName = keyHash oldkey ++ selectExtension file
|
||||
, keyVariety = newvariety
|
||||
}
|
||||
{- Upgrade to fix bad previous migration that created a
|
||||
- non-extension preserving key, with an extension
|
||||
- in its keyName. -}
|
||||
| newvariety == oldvariety && not (hasExt oldvariety) &&
|
||||
keyHash oldkey /= keyName oldkey = Just $ oldkey
|
||||
{ keyName = keyHash oldkey
|
||||
}
|
||||
| otherwise = Nothing
|
||||
where
|
||||
migratable = oldvariety /= newvariety
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue