Skip to content

Commit 6d6d79f

Browse files
committed
fix upload-abort in shares; closes #347
1 parent 9c19753 commit 6d6d79f

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

copyparty/httpcli.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5363,6 +5363,7 @@ def tx_ups(self) -> bool:
53635363
else:
53645364
shr_dbv = None
53655365

5366+
wret: dict[str, Any] = {}
53665367
ret: list[dict[str, Any]] = []
53675368
t0 = time.time()
53685369
lim = time.time() - self.args.unpost
@@ -5384,7 +5385,13 @@ def tx_ups(self) -> bool:
53845385
x = self.conn.hsrv.broker.ask(
53855386
"up2k.get_unfinished_by_user", self.uname, "" if bad_xff else self.ip
53865387
)
5387-
uret = x.get()
5388+
zdsa: dict[str, Any] = x.get()
5389+
uret: list[dict[str, Any]] = []
5390+
if "timeout" in zdsa:
5391+
wret["nou"] = 1
5392+
else:
5393+
uret = zdsa["f"]
5394+
nu = len(uret)
53885395

53895396
if not self.args.unpost:
53905397
allvols = []
@@ -5430,6 +5437,8 @@ def tx_ups(self) -> bool:
54305437

54315438
if len(ret) > 2000:
54325439
ret = ret[:2000]
5440+
if len(ret) >= 2000:
5441+
wret["oc"] = 1
54335442

54345443
for rv in ret:
54355444
rv["vp"] = quotep(rv["vp"])
@@ -5449,6 +5458,13 @@ def tx_ups(self) -> bool:
54495458
)
54505459
rv["vp"] += "?k=" + fk[:nfk]
54515460

5461+
if not allvols:
5462+
wret["noc"] = 1
5463+
ret = []
5464+
5465+
nc = len(ret)
5466+
ret = uret + ret
5467+
54525468
if shr_dbv:
54535469
# translate vpaths from share-target to share-url
54545470
# to satisfy access checks
@@ -5463,12 +5479,11 @@ def tx_ups(self) -> bool:
54635479
for v in ret:
54645480
v["vp"] = self.args.SR + v["vp"]
54655481

5466-
if not allvols:
5467-
ret = [{"kinshi": 1}]
5468-
5469-
jtxt = '{"u":%s,"c":%s}' % (uret, json.dumps(ret, separators=(",\n", ": ")))
5470-
zi = len(uret.split('\n"pd":')) - 1
5471-
self.log("%s #%d+%d %.2fsec" % (lm, zi, len(ret), time.time() - t0))
5482+
wret["f"] = ret
5483+
wret["nu"] = nu
5484+
wret["nc"] = nc
5485+
jtxt = json.dumps(wret, separators=(",\n", ": "))
5486+
self.log("%s #%d+%d %.2fsec" % (lm, nu, nc, time.time() - t0))
54725487
self.reply(jtxt.encode("utf-8", "replace"), mime="application/json")
54735488
return True
54745489

copyparty/up2k.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,14 @@ def find_job_by_ap(self, ptop: str, ap: str) -> str:
399399

400400
return "{}"
401401

402-
def get_unfinished_by_user(self, uname, ip) -> str:
402+
def get_unfinished_by_user(self, uname, ip) -> dict[str, Any]:
403+
# returns dict due to ExceptionalQueue
403404
if PY2 or not self.reg_mutex.acquire(timeout=2):
404-
return '[{"timeout":1}]'
405+
return {"timeout":1}
405406

406407
ret: list[tuple[int, str, int, int, int]] = []
407408
userset = set([(uname or "\n"), "*"])
409+
n = 1000
408410
try:
409411
for ptop, tab2 in self.registry.items():
410412
cfg = self.flags.get(ptop, {}).get("u2abort", 1)
@@ -419,7 +421,6 @@ def get_unfinished_by_user(self, uname, ip) -> str:
419421
or (addr and addr != job["addr"])
420422
):
421423
continue
422-
423424
zt5 = (
424425
int(job["t0"]),
425426
djoin(job["vtop"], job["prel"], job["name"]),
@@ -428,6 +429,9 @@ def get_unfinished_by_user(self, uname, ip) -> str:
428429
len(job["hash"]),
429430
)
430431
ret.append(zt5)
432+
n -= 1
433+
if not n:
434+
break
431435
finally:
432436
self.reg_mutex.release()
433437

@@ -444,7 +448,7 @@ def get_unfinished_by_user(self, uname, ip) -> str:
444448
}
445449
for (at, vp, sz, nn, nh) in ret
446450
]
447-
return json.dumps(ret2, separators=(",\n", ": "))
451+
return {"f": ret2}
448452

449453
def get_unfinished(self) -> str:
450454
if PY2 or not self.reg_mutex.acquire(timeout=0.5):

copyparty/web/browser.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12526,29 +12526,19 @@ var unpost = (function () {
1252612526
return ebi('op_unpost').innerHTML = '<p>' + L.badreply + ':</p>' + unpre(this.responseText);
1252712527
}
1252812528

12529-
if (ores.u.length == 1 && ores.u[0].timeout) {
12529+
if (ores.nou)
1253012530
html.push('<p>' + L.un_nou + '</p>');
12531-
ores.u = [];
12532-
}
1253312531

12534-
if (ores.c.length == 1 && ores.c[0].kinshi) {
12532+
if (ores.noc)
1253512533
html.push('<p>' + L.un_noc + '</p>');
12536-
ores.c = [];
12537-
}
12538-
12539-
for (var a = 0; a < ores.u.length; a++)
12540-
ores.u[a].k = 'u';
12541-
12542-
for (var a = 0; a < ores.c.length; a++)
12543-
ores.c[a].k = 'c';
1254412534

12545-
var res = ores.u.concat(ores.c);
12535+
var res = ores.f;
1254612536

1254712537
if (res.length) {
12548-
if (res.length == 2000)
12538+
if (ores.of)
1254912539
html.push("<p>" + L.un_max);
1255012540
else
12551-
html.push("<p>" + L.un_avail.format(ores.c.length, ores.u.length));
12541+
html.push("<p>" + L.un_avail.format(ores.nc, ores.nu));
1255212542

1255312543
html.push("<br />" + L.un_m2 + "</p>");
1255412544
html.push("<table><thead><tr><td></td><td>time</td><td>size</td><td>done</td><td>file</td></tr></thead><tbody>");
@@ -12565,7 +12555,7 @@ var unpost = (function () {
1256512555
'<a me="' + me + '" class="n' + a + '" n2="' + (a + mods[b]) +
1256612556
'" href="#">' + L.un_next.format(Math.min(mods[b], res.length - a)) + '</a></td></tr>');
1256712557

12568-
var done = res[a].k == 'c';
12558+
var done = res[a].pd === undefined;
1256912559
html.push(
1257012560
'<tr><td><a me="' + me + '" class="n' + a + '" href="#">' + (done ? L.un_del : L.un_abrt) + '</a></td>' +
1257112561
'<td>' + unix2iso(res[a].at) + '</td>' +

0 commit comments

Comments
 (0)