This removes ambiguity, because while someone might have "WORM--foo" in a
file that's not intended to be a git-annex pointer file,
"annex/objects/WORM--foo" is less likely.
Also,
664cc987e806800ef46794f356003321170c1060 had a caveat about symlink
targets being parsed as pointer files, and now the same parser is used for
both.
I did not include any hash directories before the key in the pointer file,
as they're not needed. However, if they were included, the parser would
still work ok.
{- From ref to a symlink or a pointer file, get the key. -}
catKey :: Ref -> Annex (Maybe Key)
-catKey ref = do
- o <- catObject ref
- if L.length o > maxsz
- then return Nothing -- too big
- else do
- let l = decodeBS o
- let l' = fromInternalGitPath l
- return $ if isLinkToAnnex l'
- then fileKey $ takeFileName l'
- else parsePointer l
+catKey ref = parsePointer . fromInternalGitPath . decodeBS . L.take maxsz
+ <$> catObject ref
where
-- Want to avoid buffering really big files in git into memory.
-- 8192 bytes is plenty for a pointer to a key.
{- Only look at the first line of a pointer file. -}
parsePointer :: String -> Maybe Key
-parsePointer s = headMaybe (lines s) >>= file2key
+parsePointer s = headMaybe (lines s) >>= go
+ where
+ go l
+ | isLinkToAnnex l = file2key $ takeFileName l
+ | otherwise = Nothing
{- Gets a symlink target. -}
catSymLinkTarget :: Sha -> Annex String
import Backend
import Logs.Location
import qualified Database.AssociatedFiles as AssociatedFiles
+import Git.FilePath
import qualified Data.ByteString.Lazy as B
-- Could add a newline and some text explaining this file is a pointer.
-- parsePointer only looks at the first line.
emitPointer :: Key -> IO ()
-emitPointer = putStrLn . key2file
+emitPointer k = putStrLn $ toInternalGitPath $
+ pathSeparator:objectDir </> key2file k
updateAssociatedFiles :: Key -> FilePath -> Annex ()
updateAssociatedFiles k f = do
Data:
* An annex pointer file has as its first line the git-annex key
- that it's standing in for. Subsequent lines of the file might
+ that it's standing in for (prefixed with "annex/objects/", similar to
+ an annex symlink target). Subsequent lines of the file might
be a message saying that the file's content is not currently available.
An annex pointer file is checked into the git repository the same way
that an annex symlink is checked in.