up2k-snap-load: assert .PARTIAL for unfinished

when loading up2k snaps, entries are forgotten if
the relevant file has been deleted since last run

when the entry is an unfinished upload, the file that should
be asserted is the .PARTIAL, and not the placeholder / final
filename (which, unintentionally, was the case until now)

if .PARTIAL is missing but the placeholder still exists,
the only safe alternative is to forget/disown the file,
since its state is obviously wrong and unknown
This commit is contained in:
ed 2025-01-11 11:49:53 +00:00
parent 0c0d6b2bfc
commit 467acb47bf

View file

@ -1119,6 +1119,7 @@ class Up2k(object):
reg = {} reg = {}
drp = None drp = None
emptylist = [] emptylist = []
dotpart = "." if self.args.dotpart else ""
snap = os.path.join(histpath, "up2k.snap") snap = os.path.join(histpath, "up2k.snap")
if bos.path.exists(snap): if bos.path.exists(snap):
with gzip.GzipFile(snap, "rb") as f: with gzip.GzipFile(snap, "rb") as f:
@ -1131,6 +1132,8 @@ class Up2k(object):
except: except:
pass pass
reg = reg2 # diff-golf
if reg2 and "dwrk" not in reg2[next(iter(reg2))]: if reg2 and "dwrk" not in reg2[next(iter(reg2))]:
for job in reg2.values(): for job in reg2.values():
job["dwrk"] = job["wark"] job["dwrk"] = job["wark"]
@ -1138,7 +1141,8 @@ class Up2k(object):
rm = [] rm = []
for k, job in reg2.items(): for k, job in reg2.items():
job["ptop"] = ptop job["ptop"] = ptop
if "done" in job: is_done = "done" in job
if is_done:
job["need"] = job["hash"] = emptylist job["need"] = job["hash"] = emptylist
else: else:
if "need" not in job: if "need" not in job:
@ -1146,10 +1150,13 @@ class Up2k(object):
if "hash" not in job: if "hash" not in job:
job["hash"] = [] job["hash"] = []
if is_done:
fp = djoin(ptop, job["prel"], job["name"]) fp = djoin(ptop, job["prel"], job["name"])
else:
fp = djoin(ptop, job["prel"], dotpart + job["name"] + ".PARTIAL")
if bos.path.exists(fp): if bos.path.exists(fp):
reg[k] = job if is_done:
if "done" in job:
continue continue
job["poke"] = time.time() job["poke"] = time.time()
job["busy"] = {} job["busy"] = {}