Skip to content

Commit b20c929

Browse files
authored
Merge pull request #604 from ceache/fix/sync
fix(core): sync() return should be unchrooted
2 parents f2ee305 + cbde70a commit b20c929

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

kazoo/client.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ def unchroot(self, path):
826826
"""Strip the chroot if applicable from the path."""
827827
if not self.chroot:
828828
return path
829-
829+
if self.chroot == path:
830+
return "/"
830831
if path.startswith(self.chroot):
831832
return path[len(self.chroot):]
832833
else:
@@ -839,7 +840,20 @@ def sync_async(self, path):
839840
840841
"""
841842
async_result = self.handler.async_result()
842-
self._call(Sync(_prefix_root(self.chroot, path)), async_result)
843+
844+
@wrap(async_result)
845+
def _sync_completion(result):
846+
return self.unchroot(result.get())
847+
848+
def _do_sync():
849+
result = self.handler.async_result()
850+
self._call(
851+
Sync(_prefix_root(self.chroot, path)),
852+
result
853+
)
854+
result.rawlink(_sync_completion)
855+
856+
_do_sync()
843857
return async_result
844858

845859
def sync(self, path):

kazoo/tests/test_client.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def test_connect_auth(self):
190190
client.close()
191191

192192
def test_unicode_auth(self):
193-
username = u("xe4/\hm")
194-
password = u("/\xe4hm")
193+
username = u(r"xe4/\hm")
194+
password = u(r"/\xe4hm")
195195
digest_auth = "%s:%s" % (username, password)
196196
acl = self._makeAuth(username, password, all=True)
197197

@@ -774,10 +774,11 @@ def test_ensure_path(self):
774774
client.ensure_path("/1/2/3/4")
775775
assert client.exists("/1/2/3/4")
776776

777-
@pytest.mark.skip("BUG: sync() call is not chroot'd")
778777
def test_sync(self):
779778
client = self.client
780-
assert client.sync('/') == '/'
779+
assert client.sync("/") == "/"
780+
# Albeit surprising, you can sync anything, even what does not exist.
781+
assert client.sync("/not_there") == "/not_there"
781782

782783
def test_exists(self):
783784
nodepath = "/" + uuid.uuid4().hex
@@ -1366,9 +1367,11 @@ def test_create(self):
13661367

13671368
def test_unchroot(self):
13681369
client = self._get_nonchroot_client()
1369-
client.chroot = '/a'
1370-
assert client.unchroot('/a/b') == '/b'
1371-
assert client.unchroot('/b/c') == '/b/c'
1370+
client.chroot = "/a"
1371+
# Unchroot'ing the chroot path should return "/"
1372+
assert client.unchroot("/a") == "/"
1373+
assert client.unchroot("/a/b") == "/b"
1374+
assert client.unchroot("/b/c") == "/b/c"
13721375

13731376

13741377
class TestReconfig(KazooTestCase):

0 commit comments

Comments
 (0)