avoid crashing tilde expansion on user who does not exist

git does not crash when there's a remote configured for a user who does
not exist, and this prevents git-annex from crashing too. Consider that
a user might exist on one system but not another, and the git repo be
moved between systems. So not crashing is desirable.

Note that git fetch seems to mishandle a remote path like ~foo/bar
when the user does not exist. While it does access ./~foo/bar,
and gets as far as running git-upload-pack on the path,
it then complains there is no such repo. So different parts of git seem
to be doing different things in that edge case. Anyway, git-annex does
not need to be bug-for-bug compatible with git.

Sponsored-by: Jack Hill on Patreon
This commit is contained in:
Joey Hess 2021-10-12 21:17:13 -04:00
parent 3b5ac2d0d1
commit b36cc0320e
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 5 additions and 1 deletions

View file

@ -9,6 +9,7 @@ git-annex (8.20211012) UNRELEASED; urgency=medium
by versions of git-annex older than 6.20180312.
* test: Put gpg temp home directory in system temp directory,
not filesystem being tested.
* Avoid crashing tilde expansion on user who does not exist.
-- Joey Hess <id@joeyh.name> Mon, 11 Oct 2021 14:09:13 -0400

View file

@ -184,7 +184,10 @@ expandTilde :: FilePath -> IO FilePath
#ifdef mingw32_HOST_OS
expandTilde = return
#else
expandTilde = expandt True
expandTilde p = expandt True p
-- If unable to expand a tilde, eg due to a user not existing,
-- use the path as given.
`catchNonAsync` (const (return p))
where
expandt _ [] = return ""
expandt _ ('/':cs) = do