avoid making absolute git remote path relative

When a git remote is configured with an absolute path, use that path,
rather than making it relative. If it's configured with a relative path,
use that.

Git.Construct.fromPath changed to preserve the path as-is,
rather than making it absolute. And Annex.new changed to not
convert the path to relative. Instead, Git.CurrentRepo.get
generates a relative path.

A few things that used fromAbsPath unncessarily were changed in passing to
use fromPath instead. I'm seeing fromAbsPath as a security check,
while before it was being used in some cases when the path was
known absolute already. It may be that fromAbsPath is not really needed,
but only git-annex-shell uses it now, and I'm not 100% sure that there's
not some input that would cause a relative path to be used, opening a
security hole, without the security check. So left it as-is.

Test suite passes and strace shows the configured remote url is used
unchanged in the path into it. I can't be 100% sure there's not some code
somewhere that takes an absolute path to the repo and converts it to
relative and uses it, but it seems pretty unlikely that the code paths used
for a git remote would call such code. One place I know of is gitAnnexLink,
but I'm pretty sure that git remotes never deal with annex symlinks. If
that did get called, it generates a path relative to cwd, which would have
been wrong before this change as well, when operating on a remote.
This commit is contained in:
Joey Hess 2021-02-08 13:18:01 -04:00
parent df26c9a492
commit 3a66cd715f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
9 changed files with 53 additions and 29 deletions

View file

@ -29,3 +29,7 @@ git-annex is critical infrastructure for me. There is no day without it. Thx muc
[[!tag projects/datalad]]
> So there's an OSX bug here, and git-annex has been made to use
> an absolute path to a remote when it has one, which can be used to work
> around the OSX bug. [[done]] --[[Joey]]

View file

@ -0,0 +1,18 @@
[[!comment format=mdwn
username="joey"
subject="""comment 7"""
date="2021-02-08T15:54:58Z"
content="""
Agreed, what you show in the stackoverflow post can only be an OSX bug.
Using a relative path for the current repository does avoid using long
absolute paths, and also has a minor benefit of letting the repository be
moved while git-annex is running and it still accessing the right files.
Neither benefit applies to the paths to remotes. I think the only
reason relative paths are being used for them is that the same code
is used to operate on them as on the local repository.
I've made some changes that will make it use absolute paths when the
remote has an absolute path.
"""]]