From ead31b68230b8c132f4cfad42f525f1a4271b52e Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 25 Jan 2023 20:51:02 +0000 Subject: [PATCH] add eventhook sanchecks --- copyparty/__main__.py | 9 ++++++++- copyparty/authsrv.py | 25 ++++++++++++++++++++++++- copyparty/httpcli.py | 3 ++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index d0ed16b8..c0f74d05 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -578,19 +578,26 @@ def get_sects(): each command will execute in order unless one returns non-zero optionally prefix the command with comma-sep. flags similar to -mtp: + \033[36mf\033[35m forks the process, doesn't wait for completion \033[36mc\033[35m checks return code, blocks the action if non-zero \033[36mj\033[35m provides json with info as 1st arg instead of filepath \033[36mwN\033[35m waits N sec after command has been started before continuing \033[36mtN\033[35m sets an N sec timeout before the command is abandoned + \033[36mkt\033[35m kills the entire process tree on timeout (default), \033[36mkm\033[35m kills just the main process \033[36mkn\033[35m lets it continue running until copyparty is terminated + \033[36mc0\033[35m show all process output (default) \033[36mc1\033[35m show only stderr \033[36mc2\033[35m show only stdout \033[36mc3\033[35m mute all process otput - \033[0m""" + \033[0m + except for \033[36mxm\033[0m, only one hook / one action can run at a time, + so it's recommended to use the \033[36mf\033[0m flag unless you really need + to wait for the hook to finish before continuing (without \033[36mf\033[0m + the upload speed can easily drop to 10% for small files)""" ), ], [ diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index 0876d759..f943b5c1 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -1152,9 +1152,32 @@ class AuthSrv(object): vol.flags["mth"] = self.args.mth # append additive args from argv to volflags - for name in ["mtp", "xbu", "xau", "xbr", "xar", "xbd", "xad", "xm"]: + hooks = "xbu xau xbr xar xbd xad xm".split() + for name in ["mtp"] + hooks: self._read_volflag(vol.flags, name, getattr(self.args, name), True) + for hn in hooks: + cmds = vol.flags.get(hn) + if not cmds: + continue + + ncmds = [] + for cmd in cmds: + hfs = [] + ocmd = cmd + while "," in cmd[:6]: + zs, cmd = cmd.split(",", 1) + hfs.append(zs) + + if "c" in hfs and "f" in hfs: + t = "cannot combine flags c and f; removing f from eventhook [{}]" + self.log(t.format(ocmd), 1) + hfs = [x for x in hfs if x != "f"] + ocmd = ",".join(hfs + [cmd]) + + ncmds.append(ocmd) + vol.flags[hn] = ncmds + # d2d drops all database features for a volume for grp, rm in [["d2d", "e2d"], ["d2t", "e2t"], ["d2d", "e2v"]]: if not vol.flags.get(grp, False): diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 57f0de9c..371a1a73 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -1329,6 +1329,8 @@ class HttpCli(object): if rnd and not self.args.nw: fn = self.rand_name(fdir, fn, rnd) + path = os.path.join(fdir, fn) + if is_put and not self.args.no_dav: # allow overwrite if... # * volflag 'daw' is set @@ -1337,7 +1339,6 @@ class HttpCli(object): # * file exists and is empty # * and there is no .PARTIAL - path = os.path.join(fdir, fn) tnam = fn + ".PARTIAL" if self.args.dotpart: tnam = "." + tnam