]> arthur.barton.de Git - bup.git/commitdiff
client: fix index-cache location when there's no path
authorJohannes Berg <johannes@sipsolutions.net>
Wed, 22 Jan 2020 08:25:40 +0000 (09:25 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sun, 2 Feb 2020 18:14:27 +0000 (12:14 -0600)
Putting my current tree into production, I noticed that the
index-cache was completely re-downloaded (taking a long time)
due to a change in storage location, which was broken in the
commit 85edc0f1c133 ("bup.client: accommodate python 3").

The "self.dir or b'None'" was in commit 85edc0f1c133
("bup.client: accommodate python 3") was clearly well-intended,
but also had the effect of transforming the empty string (which
evaluates to False) to b'None' instead, which is wrong since in
'bup on' cases there's no dir, but parse_remote() comes up with
an empty string instead of None.

Fix that and add a test that checks that the index location
without a dir is actually preserved as such.

Fixes: 85edc0f1c133 ("bup.client: accommodate python 3")
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/client.py
t/test-on.sh

index 9bb464c0ff60f4810ef85a640bb2e2875f6652c2..fbb92fd5aaee0f4e5a00bd3a448c7b99d1f7a0cc 100644 (file)
@@ -75,13 +75,15 @@ class Client:
             assert(not remote)
             remote = b'%s:' % is_reverse
         (self.protocol, self.host, self.port, self.dir) = parse_remote(remote)
+        # The b'None' here matches python2's behavior of b'%s' % None == 'None',
+        # python3 will (as of version 3.7.5) do the same for str ('%s' % None),
+        # but crashes instead when doing b'%s' % None.
+        cachehost = b'None' if self.host is None else self.host
+        cachedir = b'None' if self.dir is None else self.dir
         self.cachedir = git.repo(b'index-cache/%s'
                                  % re.sub(br'[^@\w]',
                                           b'_',
-                                          # FIXME: the Nones just
-                                          # match python 2's behavior
-                                          b'%s:%s' % (self.host or b'None',
-                                                      self.dir or b'None')))
+                                          b'%s:%s' % (cachehost, cachedir)))
         if is_reverse:
             self.pout = os.fdopen(3, 'rb')
             self.pin = os.fdopen(4, 'wb')
index 9943b888850c4ed207e5a08cffaccbecc525a267..24c2c383511363941c1ab263ef2836a56d0c55f2 100755 (executable)
@@ -43,4 +43,16 @@ WVPASS git cat-file commit "$commit_id" | head -n 1 \
 WVPASS bup join baz > restore-baz
 WVPASS cmp src/baz restore-baz
 
+WVSTART "index-cache"
+# the 'a-zA-Z0-9_' is '\w' from python,
+# the trailing _ is because there's no dir specified
+# and that should thus be empty
+hostname=$(bup python -c "from bup import helpers ; print(helpers.hostname().decode('iso8859-1'))")
+idxcache=$(echo "$hostname" | sed 's/[^@a-zA-Z0-9_]/_/g')_
+# there should be an index-cache now
+for idx in "$tmpdir"/bup/objects/pack/*.idx ; do
+    cachedidx="$tmpdir/bup/index-cache/$idxcache/$(basename "$idx")"
+    WVPASS cmp "$idx" "$cachedidx"
+done
+
 WVPASS rm -rf "$tmpdir"