summaryrefslogtreecommitdiff
path: root/Remote/Bup.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-04-11 12:45:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-04-11 12:45:49 -0400
commitc924542e61607d725fbfa51ffbf88d825b4d3382 (patch)
treee76c12eec3942efc2c2ab006d5737822bfb500f4 /Remote/Bup.hs
parent378f61d0ef5564aab28442f09b2462ce7013ce1b (diff)
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.
Diffstat (limited to 'Remote/Bup.hs')
-rw-r--r--Remote/Bup.hs20
1 files changed, 16 insertions, 4 deletions
diff --git a/Remote/Bup.hs b/Remote/Bup.hs
index 54aff7505..108181594 100644
--- a/Remote/Bup.hs
+++ b/Remote/Bup.hs
@@ -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 ':'