bup: Properly handle key names with spaces or other things that are not legal git refs.

Continue using the key name as bup ref name, to preserve backwards
compatability, unless it is an illegal git ref. In that case, use a sha256
of the key name instead.
This commit is contained in:
Joey Hess 2012-04-11 12:45:05 -04:00
parent 378f61d0ef
commit c924542e61
4 changed files with 22 additions and 6 deletions

View file

@ -67,8 +67,8 @@ matchingUniq ref repo = nubBy uniqref <$> matching ref repo
{- Checks if a String is a legal git ref name.
-
- The rules for this are complex; see git-check-ref-format(1) -}
legalRef :: Bool -> String -> Bool
legalRef allowonelevel s = all (== False) illegal
legal :: Bool -> String -> Bool
legal allowonelevel s = all (== False) illegal
where
illegal =
[ any ("." `isPrefixOf`) pathbits

View file

@ -17,11 +17,14 @@ import qualified Git
import qualified Git.Command
import qualified Git.Config
import qualified Git.Construct
import qualified Git.Ref
import Config
import Remote.Helper.Ssh
import Remote.Helper.Special
import Remote.Helper.Encryptable
import Crypto
import Data.ByteString.Lazy.UTF8 (fromString)
import Data.Digest.Pure.SHA
type BupRepo = String
@ -103,7 +106,7 @@ bupSplitParams r buprepo k src = do
let os = map Param $ words o
showOutput -- make way for bup output
return $ bupParams "split" buprepo
(os ++ [Param "-n", Param (show k), src])
(os ++ [Param "-n", Param (bupRef k), src])
store :: Git.Repo -> BupRepo -> Key -> Annex Bool
store r buprepo k = do
@ -121,7 +124,7 @@ storeEncrypted r buprepo (cipher, enck) k = do
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
retrieve buprepo k f = do
let params = bupParams "join" buprepo [Param $ show k]
let params = bupParams "join" buprepo [Param $ bupRef k]
liftIO $ catchBoolIO $ do
tofile <- openFile f WriteMode
pipeBup params Nothing (Just tofile)
@ -131,7 +134,7 @@ retrieveCheap _ _ _ = return False
retrieveEncrypted :: BupRepo -> (Cipher, Key) -> Key -> FilePath -> Annex Bool
retrieveEncrypted buprepo (cipher, enck) _ f = do
let params = bupParams "join" buprepo [Param $ show enck]
let params = bupParams "join" buprepo [Param $ bupRef enck]
liftIO $ catchBoolIO $ do
(pid, h) <- hPipeFrom "bup" $ toCommand params
withDecryptedContent cipher (L.hGetContents h) $ L.writeFile f
@ -158,7 +161,7 @@ checkPresent r bupr k
where
params =
[ Params "show-ref --quiet --verify"
, Param $ "refs/heads/" ++ show k]
, Param $ "refs/heads/" ++ bupRef k]
{- Store UUID in the annex.uuid setting of the bup repository. -}
storeBupUUID :: UUID -> BupRepo -> Annex ()
@ -230,5 +233,14 @@ bup2GitRemote r
| "/" `isPrefixOf` d = d
| otherwise = "/~/" ++ d
{- Converts a key into a git ref name, which bup-split -n will use to point
- to it. -}
bupRef :: Key -> String
bupRef k
| Git.Ref.legal True shown = shown
| otherwise = "git-annex-" ++ showDigest (sha256 (fromString shown))
where
shown = show k
bupLocal :: BupRepo -> Bool
bupLocal = notElem ':'

2
debian/changelog vendored
View file

@ -1,6 +1,8 @@
git-annex (3.20120407) UNRELEASED; urgency=low
* bugfix: Adding a dotfile also caused all non-dotfiles to be added.
* bup: Properly handle key names with spaces or other things that are
not legal git refs.
-- Joey Hess <joeyh@debian.org> Sun, 08 Apr 2012 12:23:42 -0400

View file

@ -48,3 +48,5 @@ I tried to restart my session, in case bup adds my username to a group or someth
> A workaround is to switch to the SHA256 backend
> (`git annex migrate --backend=SHA256`), which avoids spaces in its keys.
> --[[Joey]]
>> Now fixed in git. [[done]] --[[Joey]]