From 482dd7a938c1e0dd15580f1baaf054d64b63cfce Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 5 Mar 2021 00:00:22 +0100 Subject: [PATCH] v0.9.3 --- copyparty/__version__.py | 2 +- copyparty/httpcli.py | 4 ++-- tests/test_vfs.py | 37 ++++++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/copyparty/__version__.py b/copyparty/__version__.py index bfbaa49b..43984fda 100644 --- a/copyparty/__version__.py +++ b/copyparty/__version__.py @@ -1,6 +1,6 @@ # coding: utf-8 -VERSION = (0, 9, 2) +VERSION = (0, 9, 3) CODENAME = "the strongest music server" BUILD_DT = (2021, 3, 4) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 1df76f16..a49dd768 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1119,7 +1119,7 @@ def gen_tree(self, top, target): try: vn, rem = self.auth.vfs.get(top, self.uname, True, False) - fsroot, vfs_ls, vfs_virt = vn.ls(rem, self.uname, not self.args.no_sendfile) + fsroot, vfs_ls, vfs_virt = vn.ls(rem, self.uname, not self.args.no_scandir) except: vfs_ls = [] vfs_virt = {} @@ -1175,7 +1175,7 @@ def tx_browser(self): return self.tx_file(abspath) - fsroot, vfs_ls, vfs_virt = vn.ls(rem, self.uname, not self.args.no_sendfile) + fsroot, vfs_ls, vfs_virt = vn.ls(rem, self.uname, not self.args.no_scandir) stats = {k: v for k, v in vfs_ls} vfs_ls = [x[0] for x in vfs_ls] vfs_ls.extend(vfs_virt.keys()) diff --git a/tests/test_vfs.py b/tests/test_vfs.py index 993c346c..11a511a7 100644 --- a/tests/test_vfs.py +++ b/tests/test_vfs.py @@ -16,6 +16,12 @@ from copyparty import util +class Cfg(Namespace): + def __init__(self, a=[], v=[], c=None): + ex = {k: False for k in "e2d e2ds e2dsa e2t e2ts e2tsr mte".split()} + super(Cfg, self).__init__(a=a, v=v, c=c, **ex) + + class TestVFS(unittest.TestCase): def dump(self, vfs): print(json.dumps(vfs, indent=4, sort_keys=True, default=lambda o: o.__dict__)) @@ -35,7 +41,13 @@ def undot(self, vfs, query, response): def ls(self, vfs, vpath, uname): """helper for resolving and listing a folder""" vn, rem = vfs.get(vpath, uname, True, False) - return vn.ls(rem, uname) + r1 = vn.ls(rem, uname, False) + r2 = vn.ls(rem, uname, False) + self.assertEqual(r1, r2) + + fsdir, real, virt = r1 + real = [x[0] for x in real] + return fsdir, real, virt def runcmd(self, *argv): p = sp.Popen(argv, stdout=sp.PIPE, stderr=sp.PIPE) @@ -102,7 +114,7 @@ def test(self): f.write(fn) # defaults - vfs = AuthSrv(Namespace(c=None, a=[], v=[]), self.log).vfs + vfs = AuthSrv(Cfg(), self.log).vfs self.assertEqual(vfs.nodes, {}) self.assertEqual(vfs.vpath, "") self.assertEqual(vfs.realpath, td) @@ -110,7 +122,7 @@ def test(self): self.assertEqual(vfs.uwrite, ["*"]) # single read-only rootfs (relative path) - vfs = AuthSrv(Namespace(c=None, a=[], v=["a/ab/::r"]), self.log).vfs + vfs = AuthSrv(Cfg(v=["a/ab/::r"]), self.log).vfs self.assertEqual(vfs.nodes, {}) self.assertEqual(vfs.vpath, "") self.assertEqual(vfs.realpath, os.path.join(td, "a", "ab")) @@ -118,9 +130,7 @@ def test(self): self.assertEqual(vfs.uwrite, []) # single read-only rootfs (absolute path) - vfs = AuthSrv( - Namespace(c=None, a=[], v=[td + "//a/ac/../aa//::r"]), self.log - ).vfs + vfs = AuthSrv(Cfg(v=[td + "//a/ac/../aa//::r"]), self.log).vfs self.assertEqual(vfs.nodes, {}) self.assertEqual(vfs.vpath, "") self.assertEqual(vfs.realpath, os.path.join(td, "a", "aa")) @@ -129,7 +139,7 @@ def test(self): # read-only rootfs with write-only subdirectory (read-write for k) vfs = AuthSrv( - Namespace(c=None, a=["k:k"], v=[".::r:ak", "a/ac/acb:a/ac/acb:w:ak"]), + Cfg(a=["k:k"], v=[".::r:ak", "a/ac/acb:a/ac/acb:w:ak"]), self.log, ).vfs self.assertEqual(len(vfs.nodes), 1) @@ -192,7 +202,10 @@ def test(self): self.assertEqual(list(virt), []) # admin-only rootfs with all-read-only subfolder - vfs = AuthSrv(Namespace(c=None, a=["k:k"], v=[".::ak", "a:a:r"]), self.log,).vfs + vfs = AuthSrv( + Cfg(a=["k:k"], v=[".::ak", "a:a:r"]), + self.log, + ).vfs self.assertEqual(len(vfs.nodes), 1) self.assertEqual(vfs.vpath, "") self.assertEqual(vfs.realpath, td) @@ -211,9 +224,7 @@ def test(self): # breadth-first construction vfs = AuthSrv( - Namespace( - c=None, - a=[], + Cfg( v=[ "a/ac/acb:a/ac/acb:w", "a:a:w", @@ -234,7 +245,7 @@ def test(self): self.undot(vfs, "./.././foo/..", "") # shadowing - vfs = AuthSrv(Namespace(c=None, a=[], v=[".::r", "b:a/ac:r"]), self.log).vfs + vfs = AuthSrv(Cfg(v=[".::r", "b:a/ac:r"]), self.log).vfs fsp, r1, v1 = self.ls(vfs, "", "*") self.assertEqual(fsp, td) @@ -271,7 +282,7 @@ def test(self): ).encode("utf-8") ) - au = AuthSrv(Namespace(c=[cfg_path], a=[], v=[]), self.log) + au = AuthSrv(Cfg(c=[cfg_path]), self.log) self.assertEqual(au.user["a"], "123") self.assertEqual(au.user["asd"], "fgh:jkl") n = au.vfs