From 506ffea5e6a69e831680f0778c3f65cc07766cb5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 6 Aug 2020 20:14:30 -0400 Subject: [PATCH] stop symlink check once the top of the working tree is reached Avoid complaining that a file with "is beyond a symbolic link" when the filepath is absolute and the symlink in question is not actually inside the git repository. This assumes that inodes remain stable while the command is running. I think they always will, the filesystems where they are unstable change them across mounts. (If inodes were not stable, it would just complain about symlinks in the path that are not inside the working tree.) (On windows, I don't want to assume anything about inodes, they could be random numbers for all I know. But if they were, this would still be ok, as long as windows doesn't have symlinks that are detected by isSymbolicLink. Which seems a fair bet.) --- CHANGELOG | 3 ++ CmdLine/Seek.hs | 28 ++++++++++++++----- ...k_error_when_link_is_upstream_of_repo.mdwn | 2 ++ ..._9ac6e3436ab4866993ebf4e469b13636._comment | 12 ++++++++ 4 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo/comment_3_9ac6e3436ab4866993ebf4e469b13636._comment diff --git a/CHANGELOG b/CHANGELOG index 2c856674ff..6e7e0cf4c1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -20,6 +20,9 @@ git-annex (8.20200720.2) UNRELEASED; urgency=medium * Slightly sped up the linux standalone bundle. * importfeed: Fix reversion that caused some '.' in filenames to be replaced with '_' + * Avoid complaining that a file with "is beyond a symbolic link" + when the filepath is absolute and the symlink in question is not + actually inside the git repository. -- Joey Hess Tue, 21 Jul 2020 12:58:30 -0400 diff --git a/CmdLine/Seek.hs b/CmdLine/Seek.hs index 88a3c61212..1e8731e029 100644 --- a/CmdLine/Seek.hs +++ b/CmdLine/Seek.hs @@ -445,11 +445,12 @@ workTreeItems' (AllowHidden allowhidden) ww ps = case ww of where runcheck = do currbranch <- getCurrentBranch + stopattop <- prepviasymlink ps' <- flip filterM ps $ \p -> do relf <- liftIO $ relPathCwdToFile p ifM (not <$> (exists p <||> hidden currbranch relf)) ( prob (p ++ " not found") - , ifM (viasymlink (upFrom relf)) + , ifM (viasymlink stopattop (upFrom relf)) ( prob (p ++ " is beyond a symbolic link") , return True ) @@ -460,12 +461,25 @@ workTreeItems' (AllowHidden allowhidden) ww ps = case ww of exists p = isJust <$> liftIO (catchMaybeIO $ getSymbolicLinkStatus p) - viasymlink Nothing = return False - viasymlink (Just p) = - ifM (liftIO $ isSymbolicLink <$> getSymbolicLinkStatus p) - ( return True - , viasymlink (upFrom p) - ) + prepviasymlink = do + repotopst <- inRepo $ + maybe + (pure Nothing) + (catchMaybeIO . R.getSymbolicLinkStatus) + . Git.repoWorkTree + return $ \st -> case repotopst of + Nothing -> False + Just tst -> fileID st == fileID tst + && deviceID st == deviceID tst + + viasymlink _ Nothing = return False + viasymlink stopattop (Just p) = do + st <- liftIO $ getSymbolicLinkStatus p + if stopattop st + then return False + else if isSymbolicLink st + then return True + else viasymlink stopattop (upFrom p) hidden currbranch f | allowhidden = isJust diff --git a/doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo.mdwn b/doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo.mdwn index 3b4d06838b..f639a543dd 100644 --- a/doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo.mdwn +++ b/doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo.mdwn @@ -77,3 +77,5 @@ caller's side, but since it looks like an unintended consequence of [[!meta author=kyle]] [[!tag projects/datalad]] + +> [[fixed|done]] --[[Joey]] diff --git a/doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo/comment_3_9ac6e3436ab4866993ebf4e469b13636._comment b/doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo/comment_3_9ac6e3436ab4866993ebf4e469b13636._comment new file mode 100644 index 0000000000..64ff44e454 --- /dev/null +++ b/doc/bugs/__39__Beyond_symbolic__39___link_error_when_link_is_upstream_of_repo/comment_3_9ac6e3436ab4866993ebf4e469b13636._comment @@ -0,0 +1,12 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 3""" + date="2020-08-06T22:29:49Z" + content=""" +AFAICS, git does something like cache the stat of the directory at the top +of the working tree, and uses that to know which part to check for symlinks. +There's a lstat cache in the relevant code anyway. + +Ok, implemented it that way in git-annex, which I was able to do w/o doing +any more work per file than comparing a dev and an inode. +"""]] -- 2.39.5