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:
parent
378f61d0ef
commit
c924542e61
4 changed files with 22 additions and 6 deletions
|
@ -67,8 +67,8 @@ matchingUniq ref repo = nubBy uniqref <$> matching ref repo
|
||||||
{- Checks if a String is a legal git ref name.
|
{- Checks if a String is a legal git ref name.
|
||||||
-
|
-
|
||||||
- The rules for this are complex; see git-check-ref-format(1) -}
|
- The rules for this are complex; see git-check-ref-format(1) -}
|
||||||
legalRef :: Bool -> String -> Bool
|
legal :: Bool -> String -> Bool
|
||||||
legalRef allowonelevel s = all (== False) illegal
|
legal allowonelevel s = all (== False) illegal
|
||||||
where
|
where
|
||||||
illegal =
|
illegal =
|
||||||
[ any ("." `isPrefixOf`) pathbits
|
[ any ("." `isPrefixOf`) pathbits
|
||||||
|
|
|
@ -17,11 +17,14 @@ import qualified Git
|
||||||
import qualified Git.Command
|
import qualified Git.Command
|
||||||
import qualified Git.Config
|
import qualified Git.Config
|
||||||
import qualified Git.Construct
|
import qualified Git.Construct
|
||||||
|
import qualified Git.Ref
|
||||||
import Config
|
import Config
|
||||||
import Remote.Helper.Ssh
|
import Remote.Helper.Ssh
|
||||||
import Remote.Helper.Special
|
import Remote.Helper.Special
|
||||||
import Remote.Helper.Encryptable
|
import Remote.Helper.Encryptable
|
||||||
import Crypto
|
import Crypto
|
||||||
|
import Data.ByteString.Lazy.UTF8 (fromString)
|
||||||
|
import Data.Digest.Pure.SHA
|
||||||
|
|
||||||
type BupRepo = String
|
type BupRepo = String
|
||||||
|
|
||||||
|
@ -103,7 +106,7 @@ bupSplitParams r buprepo k src = do
|
||||||
let os = map Param $ words o
|
let os = map Param $ words o
|
||||||
showOutput -- make way for bup output
|
showOutput -- make way for bup output
|
||||||
return $ bupParams "split" buprepo
|
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 :: Git.Repo -> BupRepo -> Key -> Annex Bool
|
||||||
store r buprepo k = do
|
store r buprepo k = do
|
||||||
|
@ -121,7 +124,7 @@ storeEncrypted r buprepo (cipher, enck) k = do
|
||||||
|
|
||||||
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
|
retrieve :: BupRepo -> Key -> FilePath -> Annex Bool
|
||||||
retrieve buprepo k f = do
|
retrieve buprepo k f = do
|
||||||
let params = bupParams "join" buprepo [Param $ show k]
|
let params = bupParams "join" buprepo [Param $ bupRef k]
|
||||||
liftIO $ catchBoolIO $ do
|
liftIO $ catchBoolIO $ do
|
||||||
tofile <- openFile f WriteMode
|
tofile <- openFile f WriteMode
|
||||||
pipeBup params Nothing (Just tofile)
|
pipeBup params Nothing (Just tofile)
|
||||||
|
@ -131,7 +134,7 @@ retrieveCheap _ _ _ = return False
|
||||||
|
|
||||||
retrieveEncrypted :: BupRepo -> (Cipher, Key) -> Key -> FilePath -> Annex Bool
|
retrieveEncrypted :: BupRepo -> (Cipher, Key) -> Key -> FilePath -> Annex Bool
|
||||||
retrieveEncrypted buprepo (cipher, enck) _ f = do
|
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
|
liftIO $ catchBoolIO $ do
|
||||||
(pid, h) <- hPipeFrom "bup" $ toCommand params
|
(pid, h) <- hPipeFrom "bup" $ toCommand params
|
||||||
withDecryptedContent cipher (L.hGetContents h) $ L.writeFile f
|
withDecryptedContent cipher (L.hGetContents h) $ L.writeFile f
|
||||||
|
@ -158,7 +161,7 @@ checkPresent r bupr k
|
||||||
where
|
where
|
||||||
params =
|
params =
|
||||||
[ Params "show-ref --quiet --verify"
|
[ 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. -}
|
{- Store UUID in the annex.uuid setting of the bup repository. -}
|
||||||
storeBupUUID :: UUID -> BupRepo -> Annex ()
|
storeBupUUID :: UUID -> BupRepo -> Annex ()
|
||||||
|
@ -230,5 +233,14 @@ bup2GitRemote r
|
||||||
| "/" `isPrefixOf` d = d
|
| "/" `isPrefixOf` d = d
|
||||||
| otherwise = "/~/" ++ 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 :: BupRepo -> Bool
|
||||||
bupLocal = notElem ':'
|
bupLocal = notElem ':'
|
||||||
|
|
2
debian/changelog
vendored
2
debian/changelog
vendored
|
@ -1,6 +1,8 @@
|
||||||
git-annex (3.20120407) UNRELEASED; urgency=low
|
git-annex (3.20120407) UNRELEASED; urgency=low
|
||||||
|
|
||||||
* bugfix: Adding a dotfile also caused all non-dotfiles to be added.
|
* 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
|
-- Joey Hess <joeyh@debian.org> Sun, 08 Apr 2012 12:23:42 -0400
|
||||||
|
|
||||||
|
|
|
@ -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
|
> A workaround is to switch to the SHA256 backend
|
||||||
> (`git annex migrate --backend=SHA256`), which avoids spaces in its keys.
|
> (`git annex migrate --backend=SHA256`), which avoids spaces in its keys.
|
||||||
> --[[Joey]]
|
> --[[Joey]]
|
||||||
|
|
||||||
|
>> Now fixed in git. [[done]] --[[Joey]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue