Bugfix: Keys could be received into v1 annexes from v2 annexes, via v1 git-annex-shell. This results in some oddly named keys in the v1 annex. Recognise and fix those keys when upgrading, instead of crashing.
This commit is contained in:
parent
9d86d02b3d
commit
016eea0280
3 changed files with 31 additions and 19 deletions
|
@ -16,6 +16,7 @@ import System.FilePath
|
||||||
import Data.String.Utils
|
import Data.String.Utils
|
||||||
import System.Posix.Types
|
import System.Posix.Types
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Data.Char
|
||||||
|
|
||||||
import Key
|
import Key
|
||||||
import Content
|
import Content
|
||||||
|
@ -79,12 +80,11 @@ upgrade = do
|
||||||
moveContent :: Annex ()
|
moveContent :: Annex ()
|
||||||
moveContent = do
|
moveContent = do
|
||||||
showNote "moving content..."
|
showNote "moving content..."
|
||||||
keys <- getKeysPresent1
|
files <- getKeyFilesPresent1
|
||||||
forM_ keys move
|
forM_ files move
|
||||||
where
|
where
|
||||||
move k = do
|
move f = do
|
||||||
g <- Annex.gitRepo
|
let k = fileKey1 (takeFileName f)
|
||||||
let f = gitAnnexObjectDir g </> keyFile1 k </> keyFile1 k
|
|
||||||
let d = parentDir f
|
let d = parentDir f
|
||||||
liftIO $ allowWrite d
|
liftIO $ allowWrite d
|
||||||
liftIO $ allowWrite f
|
liftIO $ allowWrite f
|
||||||
|
@ -154,8 +154,15 @@ oldlog2key l =
|
||||||
|
|
||||||
-- WORM backend keys: "WORM:mtime:size:filename"
|
-- WORM backend keys: "WORM:mtime:size:filename"
|
||||||
-- all the rest: "backend:key"
|
-- all the rest: "backend:key"
|
||||||
|
--
|
||||||
|
-- If the file looks like "WORM:XXX-...", then it was created by mixing
|
||||||
|
-- v2 and v1; that infelicity is worked around by treating the value
|
||||||
|
-- as the v2 key that it is.
|
||||||
readKey1 :: String -> Key
|
readKey1 :: String -> Key
|
||||||
readKey1 v = Key { keyName = n , keyBackendName = b, keySize = s, keyMtime = t }
|
readKey1 v =
|
||||||
|
if mixup
|
||||||
|
then fromJust $ readKey $ join ":" $ tail bits
|
||||||
|
else Key { keyName = n , keyBackendName = b, keySize = s, keyMtime = t }
|
||||||
where
|
where
|
||||||
bits = split ":" v
|
bits = split ":" v
|
||||||
b = head bits
|
b = head bits
|
||||||
|
@ -166,7 +173,8 @@ readKey1 v = Key { keyName = n , keyBackendName = b, keySize = s, keyMtime = t }
|
||||||
s = if wormy
|
s = if wormy
|
||||||
then Just (read (bits !! 2) :: Integer)
|
then Just (read (bits !! 2) :: Integer)
|
||||||
else Nothing
|
else Nothing
|
||||||
wormy = b == "WORM"
|
wormy = head bits == "WORM"
|
||||||
|
mixup = wormy && (isUpper $ head $ bits !! 1)
|
||||||
|
|
||||||
showKey1 :: Key -> String
|
showKey1 :: Key -> String
|
||||||
showKey1 Key { keyName = n , keyBackendName = b, keySize = s, keyMtime = t } =
|
showKey1 Key { keyName = n , keyBackendName = b, keySize = s, keyMtime = t } =
|
||||||
|
@ -211,24 +219,22 @@ lookupFile1 file = do
|
||||||
skip = "skipping " ++ file ++
|
skip = "skipping " ++ file ++
|
||||||
" (unknown backend " ++ bname ++ ")"
|
" (unknown backend " ++ bname ++ ")"
|
||||||
|
|
||||||
getKeysPresent1 :: Annex [Key]
|
getKeyFilesPresent1 :: Annex [FilePath]
|
||||||
getKeysPresent1 = do
|
getKeyFilesPresent1 = do
|
||||||
g <- Annex.gitRepo
|
g <- Annex.gitRepo
|
||||||
getKeysPresent1' $ gitAnnexObjectDir g
|
getKeyFilesPresent1' $ gitAnnexObjectDir g
|
||||||
getKeysPresent1' :: FilePath -> Annex [Key]
|
getKeyFilesPresent1' :: FilePath -> Annex [FilePath]
|
||||||
getKeysPresent1' dir = do
|
getKeyFilesPresent1' dir = do
|
||||||
exists <- liftIO $ doesDirectoryExist dir
|
exists <- liftIO $ doesDirectoryExist dir
|
||||||
if (not exists)
|
if (not exists)
|
||||||
then return []
|
then return []
|
||||||
else do
|
else do
|
||||||
contents <- liftIO $ getDirectoryContents dir
|
dirs <- liftIO $ getDirectoryContents dir
|
||||||
files <- liftIO $ filterM present contents
|
let files = map (\d -> dir ++ "/" ++ d ++ "/" ++ takeFileName d) dirs
|
||||||
return $ map fileKey1 files
|
liftIO $ filterM present files
|
||||||
where
|
where
|
||||||
present d = do
|
present f = do
|
||||||
liftIO $ putStrLn $ dir ++ "/" ++ d ++ "/" ++ takeFileName d
|
result <- try $ getFileStatus f
|
||||||
result <- try $
|
|
||||||
getFileStatus $ dir ++ "/" ++ d ++ "/" ++ takeFileName d
|
|
||||||
case result of
|
case result of
|
||||||
Right s -> return $ isRegularFile s
|
Right s -> return $ isRegularFile s
|
||||||
Left _ -> return False
|
Left _ -> return False
|
||||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -6,6 +6,9 @@ git-annex (0.20110326) UNRELEASED; urgency=low
|
||||||
* Provide a less expensive version of `git annex copy --to`, enabled
|
* Provide a less expensive version of `git annex copy --to`, enabled
|
||||||
via --fast. This assumes that location tracking information is correct,
|
via --fast. This assumes that location tracking information is correct,
|
||||||
rather than contacting the remote for every file.
|
rather than contacting the remote for every file.
|
||||||
|
* Bugfix: Keys could be received into v1 annexes from v2 annexes, via
|
||||||
|
v1 git-annex-shell. This results in some oddly named keys in the v1
|
||||||
|
annex. Recognise and fix those keys when upgrading, instead of crashing.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Sat, 26 Mar 2011 14:36:16 -0400
|
-- Joey Hess <joeyh@debian.org> Sat, 26 Mar 2011 14:36:16 -0400
|
||||||
|
|
||||||
|
|
|
@ -56,3 +56,6 @@ Running the copy job again, I am still getting the same error as above (as expec
|
||||||
>>> you shouldn't delete anything. I'll simply make the v2 upgrade
|
>>> you shouldn't delete anything. I'll simply make the v2 upgrade
|
||||||
>>> detect and work around this bug.
|
>>> detect and work around this bug.
|
||||||
>>> --[[Joey]]
|
>>> --[[Joey]]
|
||||||
|
|
||||||
|
>>>> This should be fixed in current git. The scambled keys will be
|
||||||
|
>>>> fixed up on upgrade. Thanks for your patience! [[done]] --[[Joey]]
|
||||||
|
|
Loading…
Reference in a new issue