require "annex/objects/" before key in pointer files

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, 664cc987e8 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.
This commit is contained in:
Joey Hess 2015-12-07 15:45:08 -04:00
parent 664cc987e8
commit 712c9fc590
Failed to extract signature
3 changed files with 12 additions and 13 deletions

View file

@ -83,16 +83,8 @@ catFileStop = do
{- 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.
@ -102,7 +94,11 @@ catKey ref = do
{- 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

View file

@ -18,6 +18,7 @@ import Types.KeySource
import Backend
import Logs.Location
import qualified Database.AssociatedFiles as AssociatedFiles
import Git.FilePath
import qualified Data.ByteString.Lazy as B
@ -104,7 +105,8 @@ ingest file = do
-- 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

View file

@ -158,7 +158,8 @@ Using git-annex on a crippled filesystem that does not support symlinks.
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.