From 59be76cd4484d746a6a91688f8d24f799d130aa1 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 19 Sep 2021 15:00:55 +0200 Subject: [PATCH] fix basic-upload into fk-enabled folders --- copyparty/httpcli.py | 6 +++--- copyparty/svchub.py | 2 ++ copyparty/util.py | 2 +- scripts/test/smoketest.py | 43 +++++++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 21 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index c21930d9..5160f43d 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1032,7 +1032,7 @@ class HttpCli(object): bos.unlink(abspath) raise - files.append([sz, sha512_hex, p_file, fname]) + files.append([sz, sha512_hex, p_file, fname, abspath]) dbv, vrem = vfs.get_dbv(rem) self.conn.hsrv.broker.put( False, @@ -1084,14 +1084,14 @@ class HttpCli(object): jmsg["error"] = errmsg errmsg = "ERROR: " + errmsg - for sz, sha512, ofn, lfn in files: + for sz, sha512, ofn, lfn, ap in files: vsuf = "" if self.can_read and "fk" in vfs.flags: vsuf = "?k=" + gen_filekey( self.args.fk_salt, abspath, sz, - 0 if ANYWIN else bos.stat(os.path.join(vfs.realpath, lfn)).st_ino, + 0 if ANYWIN or not ap else bos.stat(ap).st_ino, )[: vfs.flags["fk"]] vpath = "{}/{}".format(upload_vpath, lfn).strip("/") diff --git a/copyparty/svchub.py b/copyparty/svchub.py index b03991df..301c84e7 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -205,6 +205,8 @@ class SvcHub(object): if self.stopping: return + # start_log_thrs(print, 0.1, 1) + self.stopping = True self.stop_req = True with self.stop_cond: diff --git a/copyparty/util.py b/copyparty/util.py index 70da5840..c534ea32 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -375,7 +375,7 @@ def stackmon(fp, ival, suffix): def start_log_thrs(logger, ival, nid): - ival = int(ival) + ival = float(ival) tname = lname = "log-thrs" if nid: tname = "logthr-n{}-i{:x}".format(nid, os.getpid()) diff --git a/scripts/test/smoketest.py b/scripts/test/smoketest.py index bb300cff..8508f127 100644 --- a/scripts/test/smoketest.py +++ b/scripts/test/smoketest.py @@ -60,7 +60,7 @@ class Cpp(object): pass -def tc1(): +def tc1(vflags): ub = "http://127.0.0.1:4321/" td = os.path.join("srv", "smoketest") try: @@ -100,17 +100,17 @@ def tc1(): for d1 in ["r", "w", "a"]: pdirs.append("{}/{}".format(td, d1)) pdirs.append("{}/{}/j".format(td, d1)) - for d2 in ["r", "w", "a"]: + for d2 in ["r", "w", "a", "c"]: d = os.path.join(td, d1, "j", d2) pdirs.append(d) os.makedirs(d) pdirs = [x.replace("\\", "/") for x in pdirs] udirs = [x.split("/", 2)[2] for x in pdirs] - perms = [x.rstrip("j/")[-1] for x in pdirs] + perms = [x.rstrip("cj/")[-1] for x in pdirs] perms = ["rw" if x == "a" else x for x in perms] for pd, ud, p in zip(pdirs, udirs, perms): - if ud[-1] == "j": + if ud[-1] == "j" or ud[-1] == "c": continue hp = None @@ -123,29 +123,37 @@ def tc1(): hp = "-" hpaths[ud] = os.path.join(pd, ".hist") - arg = "{}:{}:{}".format(pd, ud, p, hp) + arg = "{}:{}:{}".format(pd, ud, p) if hp: arg += ":c,hist=" + hp - args += ["-v", arg] + args += ["-v", arg + vflags] # return cpp = Cpp(args) CPP.append(cpp) cpp.await_idle(ub, 3) - for d in udirs: + for d, p in zip(udirs, perms): vid = ovid + "\n{}".format(d).encode("utf-8") - try: - requests.post(ub + d, data={"act": "bput"}, files={"f": ("a.h264", vid)}) - except: - pass + r = requests.post( + ub + d, + data={"act": "bput"}, + files={"f": (d.replace("/", "") + ".h264", vid)}, + ) + c = r.status_code + if c == 200 and p not in ["w", "rw"]: + raise Exception("post {} with perm {} at {}".format(c, p, d)) + elif c == 403 and p not in ["r"]: + raise Exception("post {} with perm {} at {}".format(c, p, d)) + elif c not in [200, 403]: + raise Exception("post {} with perm {} at {}".format(c, p, d)) cpp.clean() # GET permission for d, p in zip(udirs, perms): - u = "{}{}/a.h264".format(ub, d) + u = "{}{}/{}.h264".format(ub, d, d.replace("/", "")) r = requests.get(u) ok = bool(r) if ok != (p in ["rw"]): @@ -153,14 +161,14 @@ def tc1(): # stat filesystem for d, p in zip(pdirs, perms): - u = "{}/a.h264".format(d) + u = "{}/{}.h264".format(d, d.split("test/")[-1].replace("/", "")) ok = os.path.exists(u) if ok != (p in ["rw", "w"]): raise Exception("stat {} with perm {} at {}".format(ok, p, u)) # GET thumbnail, vreify contents for d, p in zip(udirs, perms): - u = "{}{}/a.h264?th=j".format(ub, d) + u = "{}{}/{}.h264?th=j".format(ub, d, d.replace("/", "")) r = requests.get(u) ok = bool(r and r.content[:3] == b"\xff\xd8\xff") if ok != (p in ["rw"]): @@ -192,9 +200,9 @@ def tc1(): cpp.stop(True) -def run(tc): +def run(tc, *a): try: - tc() + tc(*a) finally: try: CPP[0].stop(False) @@ -203,7 +211,8 @@ def run(tc): def main(): - run(tc1) + run(tc1, "") + run(tc1, ":c,fk") if __name__ == "__main__":