]> arthur.barton.de Git - bup.git/commitdiff
--remote parameter requires a colon
authorDavid Roda <davidcroda@gmail.com>
Wed, 8 Sep 2010 12:58:09 +0000 (08:58 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 8 Sep 2010 18:50:24 +0000 (11:50 -0700)
This patch checks for the presence of a colon if the --remote option
is used in bup save, bup split, bup join, and bup init.  Even though
specifying *only* a pathname without a hostname: is perfectly valid,
it's confusing to allow users to do so, because if they specify
"-r hostname" it will be treated as a path and thus give them a
confusing error message. Requiring a colon will avoid this.

It adds a few test cases to demonstrate that the code
works properly.

It also wraps the remote connection in a try except to prevent
a traceback if there is an error (so far I have only seen this
happen with an invalid bup dir parameter)

And I added the netbeans project folder to gitignore

Signed-off-by: David Roda <davidcroda@gmail.com>
.gitignore
cmd/init-cmd.py
cmd/join-cmd.py
cmd/save-cmd.py
cmd/split-cmd.py
t/test.sh

index 00cdc9ecac340a8064efb39fe4c8e098fe7c4e6c..47e1e2edf7f9c4c21e03096fc0a17f73fdb1b29f 100644 (file)
@@ -16,3 +16,4 @@ out2[tc]
 *.tmp
 /build
 *.swp
+nbproject
index 04f32484d6bd78a6ad2c37022e5ac8af6cedd6a8..e00574a9fbab9b9213ea90745615ff2ee38b3e39 100755 (executable)
@@ -15,9 +15,14 @@ if extra:
 
 
 if opt.remote:
+    if opt.remote and opt.remote.find(":") == -1:
+        o.fatal("--remote argument must contain a colon")
     git.init_repo()  # local repo
     git.check_repo_or_die()
-    cli = client.Client(opt.remote, create=True)
+    try:
+        cli = client.Client(opt.remote, create=True)
+    except client.ClientError:
+        o.fatal("server exited unexpectedly; see errors above")
     cli.close()
 else:
     git.init_repo()
index 81febac4b23c39b3cd3d973e93064eb9f477bd45..d2cc888cd3020a4404f62aaf37950d848d64077e 100755 (executable)
@@ -20,7 +20,12 @@ if not extra:
 ret = 0
 
 if opt.remote:
-    cli = client.Client(opt.remote)
+    if opt.remote and opt.remote.find(":") == -1:
+        o.fatal("--remote argument must contain a colon")
+    try:
+        cli = client.Client(opt.remote)
+    except client.ClientError:
+        o.fatal("server exited unexpectedly; see errors above")
     cat = cli.cat
 else:
     cp = git.CatPipe()
index b1376b9a4f59981037899f7a267f07159fc02d46..cf8a613bfa270d6cad3924a794198a10164cb674 100755 (executable)
@@ -7,7 +7,7 @@ from bup.helpers import *
 optspec = """
 bup save [-tc] [-n name] <filenames...>
 --
-r,remote=  remote repository path
+r,remote=  hostname:/path/to/repo of remote repository
 t,tree     output a tree id
 c,commit   output a commit id
 n,name=    name of backup set to update (if any)
@@ -36,7 +36,12 @@ if is_reverse and opt.remote:
 
 refname = opt.name and 'refs/heads/%s' % opt.name or None
 if opt.remote or is_reverse:
-    cli = client.Client(opt.remote)
+    if opt.remote and opt.remote.find(":") == -1:
+        o.fatal("--remote argument must contain a colon")
+    try:
+        cli = client.Client(opt.remote)
+    except client.ClientError:
+        o.fatal("server exited unexpectedly; see errors above")
     oldref = refname and cli.read_ref(refname) or None
     w = cli.new_packwriter()
 else:
index 5a3ea92808e378ec9a4ac03471eece34fa9a9784..4bbd58e18f70be2a70c18317a733d3be7d47de40 100755 (executable)
@@ -57,7 +57,12 @@ refname = opt.name and 'refs/heads/%s' % opt.name or None
 if opt.noop or opt.copy:
     cli = pack_writer = oldref = None
 elif opt.remote or is_reverse:
-    cli = client.Client(opt.remote)
+    if opt.remote and opt.remote.find(":") == -1:
+        o.fatal("--remote argument must contain a colon")
+    try:
+        cli = client.Client(opt.remote)
+    except client.ClientError:
+        o.fatal("server exited unexpectedly; see errors above")
     oldref = refname and cli.read_ref(refname) or None
     pack_writer = cli.new_packwriter()
 else:
index 1a904ae1fd167b78fe27146f01d9d256da6feffc..acfdda5093a3ab3a961a57bd8476381637f692d8 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -116,6 +116,10 @@ WVPASSEQ "$tree1" "$tree2"
 WVPASSEQ "$(bup index -s / | grep ^D)" ""
 tree3=$(bup save -t /)
 WVPASSEQ "$tree1" "$tree3"
+WVFAIL bup save -r localhost -n r-test $D
+WVPASS bup save -r :$BUP_DIR -n r-test $D
+WVFAIL bup save -r :$BUP_DIR/fake/path -n r-test $D
+WVFAIL bup save -r :$BUP_DIR -n r-test $D/fake/path
 
 WVSTART "split"
 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp
@@ -125,9 +129,10 @@ WVPASS bup midx -f
 WVPASS bup margin
 WVPASS bup split -t t/testfile2 >tags2t.tmp
 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
-WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
+WVFAIL bup split -r $BUP_DIR -c t/testfile2 >tags2c.tmp
+WVPASS bup split -r :$BUP_DIR -c t/testfile2 >tags2c.tmp
 WVPASS ls -lR \
-   | WVPASS bup split -r "$BUP_DIR" -c --fanout 3 --max-pack-objects 3 -n lslr
+   | WVPASS bup split -r :$BUP_DIR -c --fanout 3 --max-pack-objects 3 -n lslr
 WVPASS bup ls
 WVFAIL bup ls /does-not-exist
 WVPASS bup ls /lslr
@@ -146,7 +151,8 @@ WVSTART "join"
 WVPASS bup join $(cat tags1.tmp) >out1.tmp
 WVPASS bup join <tags2.tmp >out2.tmp
 WVPASS bup join <tags2t.tmp >out2t.tmp
-WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
+WVFAIL bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
+WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
 WVPASS diff -u t/testfile1 out1.tmp
 WVPASS diff -u t/testfile2 out2.tmp
 WVPASS diff -u t/testfile2 out2t.tmp