git-annex/Assistant
Joey Hess 6a9e923c74
fix handling of linked worktrees on filesystems w/o symlinks
Fix bug in handling of linked worktrees on filesystems not supporting
symlinks, that caused annexed file content to be stored in the wrong
location inside the git directory, and also caused pointer files to not get
populated.

This parameterizes functions in Annex.Locations with a GitLocationMaker.
The uses of standardGitLocationMaker are in cases where the path returned
by a function should not change when in a linked worktree. For example,
gitAnnexLink uses standardGitLocationMaker because symlink targets should
always be to ".git/annex/objects" paths, even when in a linked worktree.
Hopefully I have gotten all uses of standardGitLocationMaker right.

This also assumes that all path construction to the annex directory
is done via the functions in Annex.Locations, and there is no other,
ad-hoc construction elsewhere. Thankfully, Annex.Locations has been around
since the beginning, and has been used consistently. I think.

---

In fixupUnusualRepos, when symlinks are supported, the .git file is replaced
with a symlink to the linked worktree git directory. And in that directory,
an "annex" symlink points to the main annex directory. In that case,
it's not necessary to set mainWorkTreePath. It would be ok to set it,
but not setting it in that case allows an optimisation of avoiding reading
the "commondir" file.

The change to make fixupUnusualRepos set mainWorkTreePath when the
repository is not initialized yet is done in case the initialization itself
writes to the annex directory. If that were the case, without setting
mainWorkTreePath, the annex symlink would not be set up yet, and so
it might have created the annex directory in the wrong place. Currently
that didn't happen, but now that mainWorkTreePath is available, using it
here avoids any such later problem.

---

This commit does not deal with the mess of a worktree that has
experienced this bug before. In particular, if `git-annex get` were
run in such a worktree, it would have stored the object files in the
linked worktree's git directory, rather than in the main git directory.
Such misplaced object files need to be dealt with; the plan is to make
git-annex fsck notice and fix them.

A worktree that has experienced this bug before will contain unpopulated
pointer files. Those may eventually get fixed up in regular usage of
git-annex, but git-annex fsck will also fix them up.

---

Finally, this has me pondering if all of git-annex's state files should
really be stored in one common place across all linked worktrees. Should
perhaps state files that are specific to the worktree be stored per-worktree?
That has not been the case when using git-annex on filesystems supporting
symlinks, but it *has* been the case on filesystems not supporting
symlinks. Perhaps this leads to some other buggy behavior in some cases.
Or perhaps to extra work being done.

For example, the keys database has an associated files table. Which depends
on the worktree. But reconcileStaged updates that table, so when git-annex
is used first in one worktree and then in another one, reconcileStaged will
update the table to reflect the current worktree. Which is extra work each
time a different worktree is used. But also, what if two git-annex
processes are running at the same time, in separate worktrees? Probably
this needs more thought and investigation.

So there is a risk that this commit exposes such buggy behavior in a
situation where it didn't happen before, due to the filesystem not
supporting symlinks. But, given how much this bug crippled using linked
worktrees in such a situation, I doubt that many people have been doing
that.
2025-07-14 13:20:39 -04:00
..
Alert Apply codespell -w throughout 2023-03-17 15:14:58 -04:00
Install optimise literalOsPath 2025-01-27 16:36:29 -04:00
Pairing more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
Threads OSX build fixes 2025-02-17 14:04:08 -04:00
Types more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
WebApp webapp: Rename "Upgrade Repository" to "Convert Repository" 2025-06-24 12:33:48 -04:00
Alert.hs more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
BranchChange.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Changes.hs more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
Commits.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Common.hs use fastDebug everywhere it can be used 2021-04-06 15:41:24 -04:00
CredPairCache.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
DaemonStatus.hs parsePOSIXTime ByteString conversion 2025-01-22 16:42:09 -04:00
DeleteRemote.hs filter out control characters in error messages 2023-04-10 13:50:51 -04:00
Drop.hs add SeekInput (not yet used) 2020-09-15 15:41:13 -04:00
Fsck.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Gpg.hs use NonEmpty for dirHashes 2024-09-26 18:15:00 -04:00
Install.hs OSX build fixes 2025-02-17 14:04:08 -04:00
MakeRemote.hs filter out control characters in error messages 2023-04-10 13:50:51 -04:00
MakeRepo.hs more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
Monad.hs turn of PackageImports in cabal file 2022-02-25 13:16:36 -04:00
NamedThread.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Pairing.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Pushes.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
RemoteControl.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Repair.hs fix handling of linked worktrees on filesystems w/o symlinks 2025-07-14 13:20:39 -04:00
RepoProblem.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Restart.hs more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
ScanRemotes.hs update licenses from GPL to AGPL 2019-03-13 15:48:14 -04:00
Ssh.hs more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
Sync.hs convert checkAvailable to use availability rather than localpath 2023-08-16 15:57:30 -04:00
TransferQueue.hs plumb in LiveUpdate (WIP) 2024-08-23 16:35:12 -04:00
TransferSlots.hs more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
Unused.hs more OsPath conversion (749/749) 2025-02-10 14:59:20 -04:00
Upgrade.hs Added remote.name.annex-web-options config 2025-04-01 10:17:38 -04:00
WebApp.hs unified AuthToken type between webapp and tor 2016-11-22 14:18:34 -04:00