diff --git a/Annex/Link.hs b/Annex/Link.hs index 561385a5b9..321aba23cf 100644 --- a/Annex/Link.hs +++ b/Annex/Link.hs @@ -7,7 +7,7 @@ - - Pointer files are used instead of symlinks for unlocked files. - - - Copyright 2013-2021 Joey Hess + - Copyright 2013-2022 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -297,11 +297,21 @@ unableToRestage mf = unwords {- Parses a symlink target or a pointer file to a Key. -} parseLinkTargetOrPointer :: S.ByteString -> Maybe Key -parseLinkTargetOrPointer = parseLinkTarget . S8.takeWhile (not . lineend) +parseLinkTargetOrPointer = go . S8.takeWhile (not . lineend) where + go l + | isLinkToAnnex l = fileKey $ snd $ S8.breakEnd pathsep l + | otherwise = Nothing + lineend '\n' = True lineend '\r' = True lineend _ = False + + pathsep '/' = True +#ifdef mingw32_HOST_OS + pathsep '\\' = True +#endif + pathsep _ = False {- Avoid looking at more of the lazy ByteString than necessary since it - could be reading from a large file that is not a pointer file. -} @@ -310,18 +320,6 @@ parseLinkTargetOrPointerLazy b = let b' = L.take (fromIntegral maxPointerSz) b in parseLinkTargetOrPointer (L.toStrict b') -{- Parses a symlink target to a Key. -} -parseLinkTarget :: S.ByteString -> Maybe Key -parseLinkTarget l - | isLinkToAnnex l = fileKey $ snd $ S8.breakEnd pathsep l - | otherwise = Nothing - where - pathsep '/' = True -#ifdef mingw32_HOST_OS - pathsep '\\' = True -#endif - pathsep _ = False - formatPointer :: Key -> S.ByteString formatPointer k = prefix <> keyFile k <> nl where diff --git a/Assistant/Threads/Watcher.hs b/Assistant/Threads/Watcher.hs index 3f04edf57d..59f6922e3a 100644 --- a/Assistant/Threads/Watcher.hs +++ b/Assistant/Threads/Watcher.hs @@ -265,7 +265,7 @@ onAddFile' contentchanged addassociatedfile addlink samefilestatus symlinkssuppo case linktarget of Nothing -> a Just lt -> do - case parseLinkTarget lt of + case parseLinkTargetOrPointer lt of Nothing -> noop Just key -> liftAnnex $ addassociatedfile key file