2015-12-15 19:34:28 +00:00
|
|
|
{- git-annex worktree files
|
|
|
|
-
|
2021-05-31 17:40:42 +00:00
|
|
|
- Copyright 2013-2021 Joey Hess <id@joeyh.name>
|
2015-12-15 19:34:28 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2015-12-15 19:34:28 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.WorkTree where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2015-12-15 19:34:28 +00:00
|
|
|
import Annex.Link
|
|
|
|
import Annex.CatFile
|
2018-10-19 21:51:25 +00:00
|
|
|
import Annex.CurrentBranch
|
2016-10-17 18:58:33 +00:00
|
|
|
import qualified Database.Keys
|
2020-06-11 19:40:13 +00:00
|
|
|
|
2015-12-30 18:23:31 +00:00
|
|
|
{- Looks up the key corresponding to an annexed file in the work tree,
|
2015-12-15 19:34:28 +00:00
|
|
|
- by examining what the file links to.
|
|
|
|
-
|
|
|
|
- An unlocked file will not have a link on disk, so fall back to
|
|
|
|
- looking for a pointer to a key in git.
|
2018-10-19 21:51:25 +00:00
|
|
|
-
|
|
|
|
- When in an adjusted branch that may have hidden the file, looks for a
|
|
|
|
- pointer to a key in the original branch.
|
2015-12-15 19:34:28 +00:00
|
|
|
-}
|
2020-07-10 18:17:35 +00:00
|
|
|
lookupKey :: RawFilePath -> Annex (Maybe Key)
|
|
|
|
lookupKey = lookupKey' catkeyfile
|
2019-02-05 17:13:09 +00:00
|
|
|
where
|
|
|
|
catkeyfile file =
|
2019-11-26 19:27:22 +00:00
|
|
|
ifM (liftIO $ doesFileExist $ fromRawFilePath file)
|
2018-10-19 21:51:25 +00:00
|
|
|
( catKeyFile file
|
|
|
|
, catKeyFileHidden file =<< getCurrentBranch
|
2015-12-16 18:27:12 +00:00
|
|
|
)
|
2019-02-05 17:13:09 +00:00
|
|
|
|
2020-07-10 18:17:35 +00:00
|
|
|
lookupKeyNotHidden :: RawFilePath -> Annex (Maybe Key)
|
|
|
|
lookupKeyNotHidden = lookupKey' catkeyfile
|
2019-02-05 17:13:09 +00:00
|
|
|
where
|
|
|
|
catkeyfile file =
|
2019-11-26 19:27:22 +00:00
|
|
|
ifM (liftIO $ doesFileExist $ fromRawFilePath file)
|
2019-02-05 17:13:09 +00:00
|
|
|
( catKeyFile file
|
|
|
|
, return Nothing
|
|
|
|
)
|
|
|
|
|
2020-07-10 18:17:35 +00:00
|
|
|
lookupKey' :: (RawFilePath -> Annex (Maybe Key)) -> RawFilePath -> Annex (Maybe Key)
|
|
|
|
lookupKey' catkeyfile file = isAnnexLink file >>= \case
|
2019-02-05 17:13:09 +00:00
|
|
|
Just key -> return (Just key)
|
2019-08-30 17:54:57 +00:00
|
|
|
Nothing -> catkeyfile file
|
2015-12-15 19:34:28 +00:00
|
|
|
|
|
|
|
{- Modifies an action to only act on files that are already annexed,
|
|
|
|
- and passes the key on to it. -}
|
2019-11-26 19:27:22 +00:00
|
|
|
whenAnnexed :: (RawFilePath -> Key -> Annex (Maybe a)) -> RawFilePath -> Annex (Maybe a)
|
2015-12-15 19:34:28 +00:00
|
|
|
whenAnnexed a file = ifAnnexed file (a file) (return Nothing)
|
|
|
|
|
2019-11-26 19:27:22 +00:00
|
|
|
ifAnnexed :: RawFilePath -> (Key -> Annex a) -> Annex a -> Annex a
|
2020-07-10 18:17:35 +00:00
|
|
|
ifAnnexed file yes no = maybe no yes =<< lookupKey file
|
2016-10-17 18:58:33 +00:00
|
|
|
|
include locked files in the keys database associated files
Before only unlocked files were included.
The initial scan now scans for locked as well as unlocked files. This
does mean it gets a little bit slower, although I optimised it as well
as I think it can be.
reconcileStaged changed to diff from the current index to the tree of
the previous index. This lets it handle deletions as well, removing
associated files for both locked and unlocked files, which did not
always happen before.
On upgrade, there will be no recorded previous tree, so it will diff
from the empty tree to current index, and so will fully populate the
associated files, as well as removing any stale associated files
that were present due to them not being removed before.
reconcileStaged now does a bit more work. Most of the time, this will
just be due to running more often, after some change is made to the
index, and since there will be few changes since the last time, it will
not be a noticable overhead. What may turn out to be a noticable
slowdown is after changing to a branch, it has to go through the diff
from the previous index to the new one, and if there are lots of
changes, that could take a long time. Also, after adding a lot of files,
or deleting a lot of files, or moving a large subdirectory, etc.
Command.Lock used removeAssociatedFile, but now that's wrong because a
newly locked file still needs to have its associated file tracked.
Command.Rekey used removeAssociatedFile when the file was unlocked.
It could remove it also when it's locked, but it is not really
necessary, because it changes the index, and so the next time git-annex
run and accesses the keys db, reconcileStaged will run and update it.
There are probably several other places that use addAssociatedFile and
don't need to any more for similar reasons. But there's no harm in
keeping them, and it probably is a good idea to, if only to support
mixing this with older versions of git-annex.
However, mixing this and older versions does risk reconcileStaged not
running, if the older version already ran it on a given index state. So
it's not a good idea to mix versions. This problem could be dealt with
by changing the name of the gitAnnexKeysDbIndexCache, but that would
leave the old file dangling, or it would need to keep trying to remove
it.
2021-05-21 19:47:37 +00:00
|
|
|
{- Find all annexed files and update the keys database for them.
|
2016-10-17 18:58:33 +00:00
|
|
|
-
|
2021-07-30 21:46:11 +00:00
|
|
|
- Normally the keys database is updated incrementally when it's being
|
|
|
|
- opened, and changes are noticed. Calling this explicitly allows
|
|
|
|
- running the update at an earlier point.
|
2021-07-30 22:36:03 +00:00
|
|
|
-
|
|
|
|
- All that needs to be done is to open the database,
|
|
|
|
- that will result in Database.Keys.reconcileStaged
|
|
|
|
- running, and doing the work.
|
2016-10-17 18:58:33 +00:00
|
|
|
-}
|
2021-07-30 21:46:11 +00:00
|
|
|
scanAnnexedFiles :: Annex ()
|
2021-07-30 22:36:03 +00:00
|
|
|
scanAnnexedFiles = Database.Keys.runWriter (const noop)
|