cmd = withGlobalOptions [annexedMatchingOptions] $
command "migrate" SectionUtility
"switch data to different backend"
- paramPaths (withParams seek)
+ paramPaths (seek <$$> optParser)
-seek :: CmdParams -> CommandSeek
-seek = withFilesInGitAnnex ww seeker <=< workTreeItems ww
+data MigrateOptions = MigrateOptions
+ { migrateThese :: CmdParams
+ , removeSize :: Bool
+ }
+
+optParser :: CmdParamsDesc -> Parser MigrateOptions
+optParser desc = MigrateOptions
+ <$> cmdParams desc
+ <*> switch
+ ( long "remove-size"
+ <> help "remove size field from keys"
+ )
+
+seek :: MigrateOptions -> CommandSeek
+seek o = withFilesInGitAnnex ww seeker =<< workTreeItems ww (migrateThese o)
where
ww = WarnUnmatchLsFiles
seeker = AnnexedFileSeeker
- { startAction = start
+ { startAction = start o
, checkContentPresent = Nothing
, usesLocationLog = False
}
-start :: SeekInput -> RawFilePath -> Key -> CommandStart
-start si file key = do
+start :: MigrateOptions -> SeekInput -> RawFilePath -> Key -> CommandStart
+start o si file key = do
forced <- Annex.getState Annex.force
v <- Backend.getBackend (fromRawFilePath file) key
case v of
newbackend <- maybe defaultBackend return
=<< chooseBackend file
if (newbackend /= oldbackend || upgradableKey oldbackend key || forced) && exists
- then starting "migrate" (mkActionItem (key, file)) si $
- perform file key oldbackend newbackend
- else stop
+ then go False oldbackend newbackend
+ else if removeSize o && exists
+ then go True oldbackend oldbackend
+ else stop
+ where
+ go onlyremovesize oldbackend newbackend =
+ starting "migrate" (mkActionItem (key, file)) si $
+ perform onlyremovesize o file key oldbackend newbackend
{- Checks if a key is upgradable to a newer representation.
-
- data cannot get corrupted after the fsck but before the new key is
- generated.
-}
-perform :: RawFilePath -> Key -> Backend -> Backend -> CommandPerform
-perform file oldkey oldbackend newbackend = go =<< genkey (fastMigrate oldbackend)
+perform :: Bool -> MigrateOptions -> RawFilePath -> Key -> Backend -> Backend -> CommandPerform
+perform onlyremovesize o file oldkey oldbackend newbackend = go =<< genkey (fastMigrate oldbackend)
where
go Nothing = stop
go (Just (newkey, knowngoodcontent))
- | knowngoodcontent = finish newkey
- | otherwise = stopUnless checkcontent $ finish newkey
+ | knowngoodcontent = finish (removesize newkey)
+ | otherwise = stopUnless checkcontent $
+ finish (removesize newkey)
checkcontent = Command.Fsck.checkBackend oldbackend oldkey Command.Fsck.KeyPresent afile
finish newkey = ifM (Command.ReKey.linkKey file oldkey newkey)
( do
next $ Command.ReKey.cleanup file newkey
, giveup "failed creating link from old to new key"
)
+ genkey _ | onlyremovesize = return $ Just (oldkey, False)
genkey Nothing = do
content <- calcRepo $ gitAnnexLocation oldkey
let source = KeySource
genkey (Just fm) = fm oldkey newbackend afile >>= \case
Just newkey -> return (Just (newkey, True))
Nothing -> genkey Nothing
+ removesize k
+ | removeSize o = alterKey k $ \kd -> kd { keySize = Nothing }
+ | otherwise = k
afile = AssociatedFile (Just file)
--- /dev/null
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2021-11-12T16:10:01Z"
+ content="""
+Migrating to URL will not do anything since they already are url keys.
+
+This could be scripted using `git-annex examinekey` to
+convert such a key into one without a size, and then using
+`git-annex rekey`, which lets the new key for a file be specified.
+
+However, that command is a low level plumbing command, and does not copy
+over the url list from the old to the new key as migrate does (nor other
+metadata). So you would also have to use `git-annex addurl file url`
+afterwards to add the url, and use `git-annex metadata` if you have
+metadata. Very unergonomic.
+"""]]
--- /dev/null
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 2"""
+ date="2021-11-12T16:57:15Z"
+ content="""
+Implemented: `git-annex migrate --remove-size --backend=URL`
+
+Be sure to only run it on files using url keys, since it will also
+remove sizes from other keys. (Or use `--inbackend=URL` with it.)
+
+Do note that `git-annex migrate` can only migrate files whose content
+is present. If you have never downloaded those urls, and `git-annex get`
+cannot download them now, because their size has changed, you
+won't be able to migrate data you don't have. In this case, re-running
+`git-annex addurl` with `--relaxed` seems like the only option.
+"""]]