mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
up2k: add option to replace existing file
This commit is contained in:
parent
7704b9c8a2
commit
56b73dcc8a
|
@ -1540,11 +1540,6 @@ class HttpCli(object):
|
|||
if "delete" in self.uparam:
|
||||
return self.handle_rm(body)
|
||||
|
||||
# up2k-php compat
|
||||
for k in "chunkpit.php", "handshake.php":
|
||||
if self.vpath.endswith(k):
|
||||
self.vpath = self.vpath[: -len(k)]
|
||||
|
||||
name = undot(body["name"])
|
||||
if "/" in name:
|
||||
raise Pebkac(400, "your client is old; press CTRL-SHIFT-R and try again")
|
||||
|
@ -1558,6 +1553,9 @@ class HttpCli(object):
|
|||
body["addr"] = self.ip
|
||||
body["vcfg"] = dbv.flags
|
||||
|
||||
if not self.can_delete:
|
||||
body.pop("replace")
|
||||
|
||||
if rem:
|
||||
dst = vfs.canonical(rem)
|
||||
try:
|
||||
|
|
|
@ -2116,7 +2116,7 @@ class Up2k(object):
|
|||
job[k] = cj[k]
|
||||
|
||||
pdir = djoin(cj["ptop"], cj["prel"])
|
||||
job["name"] = self._untaken(pdir, cj["name"], now, cj["addr"])
|
||||
job["name"] = self._untaken(pdir, cj, now)
|
||||
dst = os.path.join(job["ptop"], job["prel"], job["name"])
|
||||
if not self.args.nw:
|
||||
bos.unlink(dst) # TODO ed pls
|
||||
|
@ -2163,7 +2163,7 @@ class Up2k(object):
|
|||
]:
|
||||
job[k] = cj[k]
|
||||
|
||||
for k in ["life"]:
|
||||
for k in ["life", "replace"]:
|
||||
if k in cj:
|
||||
job[k] = cj[k]
|
||||
|
||||
|
@ -2195,10 +2195,18 @@ class Up2k(object):
|
|||
"wark": wark,
|
||||
}
|
||||
|
||||
def _untaken(self, fdir: str, fname: str, ts: float, ip: str) -> str:
|
||||
def _untaken(self, fdir: str, job: dict[str, Any], ts: float) -> str:
|
||||
fname = job["name"]
|
||||
ip = job["addr"]
|
||||
|
||||
if self.args.nw:
|
||||
return fname
|
||||
|
||||
fp = os.path.join(fdir, fname)
|
||||
if job.get("replace") and bos.path.exists(fp):
|
||||
self.log("replacing existing file at {}".format(fp))
|
||||
bos.unlink(fp)
|
||||
|
||||
if self.args.plain_ip:
|
||||
dip = ip.replace(":", ".")
|
||||
else:
|
||||
|
@ -2973,7 +2981,7 @@ class Up2k(object):
|
|||
return
|
||||
|
||||
self.registry[job["ptop"]][job["wark"]] = job
|
||||
job["name"] = self._untaken(pdir, job["name"], job["t0"], job["addr"])
|
||||
job["name"] = self._untaken(pdir, job, job["t0"])
|
||||
# if len(job["name"].split(".")) > 8:
|
||||
# raise Exception("aaa")
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ class Cfg(Namespace):
|
|||
def __init__(self, a=None, v=None, c=None):
|
||||
ka = {}
|
||||
|
||||
ex = "daw dav_inf dav_mac e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp ed emp force_js ihead magic nid nih no_acode no_athumb no_dav no_del no_dupe no_logues no_mv no_readme no_robots no_scandir no_sync no_thumb no_vthumb no_wal no_zip nw xdev xlink xvol"
|
||||
ex = "daw dav_inf dav_mac e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp ed emp force_js ihead magic nid nih no_acode no_athumb no_dav no_del no_dupe no_logues no_mv no_readme no_robots no_scandir no_thumb no_vthumb no_zip nw xdev xlink xvol"
|
||||
ka.update(**{k: False for k in ex.split()})
|
||||
|
||||
ex = "dotpart no_rescan no_sendfile no_voldump plain_ip"
|
||||
|
@ -118,6 +118,7 @@ class Cfg(Namespace):
|
|||
v=v or [],
|
||||
c=c,
|
||||
E=E,
|
||||
dbd="wal",
|
||||
s_wr_sz=512 * 1024,
|
||||
unpost=600,
|
||||
u2sort="s",
|
||||
|
|
Loading…
Reference in a new issue