fold parseLinkTarget into parseLinkTargetOrPointer
Only one place remained that differentiated between them. It is the case that a symlink target that happens to contain a newline somehow will be treated as a link to a key truncated at the newline. This is super unlikely to happen, and since a key cannot actually contain a newline, it's as good a behavior as any. Anyway, this commit does not change the behavior there, although arguably it should be changed. Note that getAnnexLinkTarget does prevent a symlink target containing a newline. Sponsored-by: Dartmouth College's Datalad project
This commit is contained in:
parent
38816a9ae9
commit
4cd9325c2c
2 changed files with 13 additions and 15 deletions
|
@ -7,7 +7,7 @@
|
|||
-
|
||||
- Pointer files are used instead of symlinks for unlocked files.
|
||||
-
|
||||
- Copyright 2013-2021 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2013-2022 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -297,12 +297,22 @@ 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. -}
|
||||
parseLinkTargetOrPointerLazy :: L.ByteString -> Maybe Key
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue