2015-12-15 19:56:37 +00:00
|
|
|
{- git-annex v5 -> v6 upgrade support
|
2015-12-04 20:14:48 +00:00
|
|
|
-
|
2016-04-04 17:17:24 +00:00
|
|
|
- Copyright 2015-2016 Joey Hess <id@joeyh.name>
|
2015-12-04 20:14:48 +00:00
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Upgrade.V5 where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2015-12-27 19:59:59 +00:00
|
|
|
import qualified Annex
|
2015-12-04 20:14:48 +00:00
|
|
|
import Config
|
2015-12-09 19:42:16 +00:00
|
|
|
import Annex.InodeSentinal
|
2015-12-15 19:56:37 +00:00
|
|
|
import Annex.Link
|
|
|
|
import Annex.Direct
|
|
|
|
import Annex.Content
|
2015-12-27 19:59:59 +00:00
|
|
|
import Annex.CatFile
|
2015-12-15 19:56:37 +00:00
|
|
|
import qualified Database.Keys
|
|
|
|
import qualified Annex.Content.Direct as Direct
|
|
|
|
import qualified Git
|
|
|
|
import qualified Git.LsFiles
|
|
|
|
import qualified Git.Branch
|
2016-01-05 21:22:19 +00:00
|
|
|
import Git.FilePath
|
2015-12-15 19:56:37 +00:00
|
|
|
import Git.FileMode
|
2015-12-27 19:59:59 +00:00
|
|
|
import Git.Config
|
2016-04-04 17:17:24 +00:00
|
|
|
import Git.Ref
|
2015-12-22 19:20:03 +00:00
|
|
|
import Utility.InodeCache
|
2016-04-04 17:17:24 +00:00
|
|
|
import Annex.AdjustedBranch
|
2015-12-04 20:14:48 +00:00
|
|
|
|
|
|
|
upgrade :: Bool -> Annex Bool
|
|
|
|
upgrade automatic = do
|
|
|
|
unless automatic $
|
|
|
|
showAction "v5 to v6"
|
2016-01-01 19:15:15 +00:00
|
|
|
Database.Keys.scanAssociatedFiles
|
2015-12-15 19:56:37 +00:00
|
|
|
whenM isDirect $ do
|
2015-12-27 19:59:59 +00:00
|
|
|
{- Direct mode makes the same tradeoff of using less disk
|
|
|
|
- space, with less preservation of old versions of files
|
|
|
|
- as does annex.thin. -}
|
|
|
|
setConfig (annexConfig "thin") (boolConfig True)
|
|
|
|
Annex.changeGitConfig $ \c -> c { annexThin = True }
|
2015-12-15 19:56:37 +00:00
|
|
|
{- Since upgrade from direct mode changes how files
|
2016-04-04 17:17:24 +00:00
|
|
|
- are represented in git, by checking out an adjusted
|
|
|
|
- branch, commit any changes in the work tree first. -}
|
2015-12-15 19:56:37 +00:00
|
|
|
whenM stageDirect $ do
|
|
|
|
unless automatic $
|
|
|
|
showAction "committing first"
|
|
|
|
upgradeDirectCommit automatic
|
|
|
|
"commit before upgrade to annex.version 6"
|
|
|
|
setDirect False
|
2016-04-04 17:17:24 +00:00
|
|
|
cur <- fromMaybe (error "Somehow no branch is checked out")
|
|
|
|
<$> inRepo Git.Branch.current
|
2015-12-15 19:56:37 +00:00
|
|
|
upgradeDirectWorkTree
|
|
|
|
removeDirectCruft
|
2016-04-04 17:17:24 +00:00
|
|
|
{- Create adjusted branch where all files are unlocked.
|
|
|
|
- This should have the same content for each file as
|
|
|
|
- have been staged in upgradeDirectWorkTree. -}
|
2016-04-09 19:10:26 +00:00
|
|
|
AdjBranch b <- adjustBranch UnlockAdjustment cur
|
2016-04-04 17:17:24 +00:00
|
|
|
{- Since the work tree was already set up by
|
|
|
|
- upgradeDirectWorkTree, and contains unlocked file
|
|
|
|
- contents too, don't use git checkout to check out the
|
|
|
|
- adjust branch. Instead, update HEAD manually. -}
|
2016-04-09 19:10:26 +00:00
|
|
|
inRepo $ setHeadRef b
|
2015-12-04 20:14:48 +00:00
|
|
|
configureSmudgeFilter
|
2015-12-09 19:42:16 +00:00
|
|
|
-- Inode sentinal file was only used in direct mode and when
|
|
|
|
-- locking down files as they were added. In v6, it's used more
|
|
|
|
-- extensively, so make sure it exists, since old repos that didn't
|
|
|
|
-- use direct mode may not have created it.
|
|
|
|
unlessM (isDirect) $
|
|
|
|
createInodeSentinalFile True
|
2015-12-04 20:14:48 +00:00
|
|
|
return True
|
2015-12-15 19:56:37 +00:00
|
|
|
|
|
|
|
upgradeDirectCommit :: Bool -> String -> Annex ()
|
|
|
|
upgradeDirectCommit automatic msg =
|
|
|
|
void $ inRepo $ Git.Branch.commitCommand commitmode
|
|
|
|
[ Param "-m"
|
|
|
|
, Param msg
|
|
|
|
]
|
|
|
|
where
|
|
|
|
commitmode = if automatic then Git.Branch.AutomaticCommit else Git.Branch.ManualCommit
|
|
|
|
|
|
|
|
{- Walk work tree from top and convert all annex symlinks to pointer files,
|
|
|
|
- staging them in the index, and updating the work tree files with
|
|
|
|
- either the content of the object, or the pointer file content. -}
|
|
|
|
upgradeDirectWorkTree :: Annex ()
|
|
|
|
upgradeDirectWorkTree = do
|
|
|
|
top <- fromRepo Git.repoPath
|
|
|
|
(l, clean) <- inRepo $ Git.LsFiles.stagedDetails [top]
|
|
|
|
forM_ l go
|
|
|
|
void $ liftIO clean
|
|
|
|
where
|
|
|
|
go (f, Just _sha, Just mode) | isSymLink mode = do
|
2015-12-27 19:59:59 +00:00
|
|
|
-- Cannot use lookupFile here, as we're in between direct
|
|
|
|
-- mode and v6.
|
|
|
|
mk <- catKeyFile f
|
2015-12-15 19:56:37 +00:00
|
|
|
case mk of
|
|
|
|
Nothing -> noop
|
|
|
|
Just k -> do
|
|
|
|
ifM (isJust <$> getAnnexLinkTarget f)
|
|
|
|
( writepointer f k
|
|
|
|
, fromdirect f k
|
|
|
|
)
|
2016-04-14 18:30:15 +00:00
|
|
|
stagePointerFile f Nothing =<< hashPointerFile k
|
2016-01-05 21:22:19 +00:00
|
|
|
Database.Keys.addAssociatedFile k
|
|
|
|
=<< inRepo (toTopFilePath f)
|
2015-12-15 19:56:37 +00:00
|
|
|
return ()
|
|
|
|
go _ = noop
|
|
|
|
|
|
|
|
fromdirect f k = do
|
2015-12-27 19:59:59 +00:00
|
|
|
-- If linkToAnnex fails for some reason, the work tree file
|
2015-12-15 19:56:37 +00:00
|
|
|
-- still has the content; the annex object file is just
|
|
|
|
-- not populated with it. Since the work tree file
|
|
|
|
-- is recorded as an associated file, things will still
|
|
|
|
-- work that way, it's just not ideal.
|
2015-12-22 19:20:03 +00:00
|
|
|
ic <- withTSDelta (liftIO . genInodeCache f)
|
2015-12-27 19:59:59 +00:00
|
|
|
void $ linkToAnnex k f ic
|
2015-12-15 19:56:37 +00:00
|
|
|
writepointer f k = liftIO $ do
|
|
|
|
nukeFile f
|
|
|
|
writeFile f (formatPointer k)
|
|
|
|
|
|
|
|
{- Remove all direct mode bookkeeping files. -}
|
|
|
|
removeDirectCruft :: Annex ()
|
|
|
|
removeDirectCruft = mapM_ go =<< getKeysPresent InAnywhere
|
|
|
|
where
|
|
|
|
go k = do
|
|
|
|
Direct.removeInodeCache k
|
|
|
|
Direct.removeAssociatedFiles k
|