From 2077dca66f588810df0766aa5b12c3c7edf40038 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 8 Dec 2023 00:54:57 +0000 Subject: [PATCH] u2c: when deleting from server, heed request size limit --- bin/u2c.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/u2c.py b/bin/u2c.py index a166d786..2c8c38b7 100755 --- a/bin/u2c.py +++ b/bin/u2c.py @@ -907,12 +907,23 @@ class Ctl(object): dp = os.path.join(top, rd) lnodes = set(os.listdir(dp)) bnames = [x for x in ls if x not in lnodes] - if bnames: - vpath = self.ar.url.split("://")[-1].split("/", 1)[-1] - names = [x.decode("utf-8", "replace") for x in bnames] - locs = [vpath + srd + "/" + x for x in names] - print("DELETING ~{0}/#{1}".format(srd, len(names))) - req_ses.post(self.ar.url + "?delete", json=locs) + vpath = self.ar.url.split("://")[-1].split("/", 1)[-1] + names = [x.decode("utf-8", "replace") for x in bnames] + locs = [vpath + srd + "/" + x for x in names] + while locs: + req = locs + while req: + print("DELETING ~%s/#%s" % (srd, len(req))) + r = req_ses.post(self.ar.url + "?delete", json=req) + if r.status_code == 413 and "json 2big" in r.text: + print(" (delete request too big; slicing...)") + req = req[: len(req) // 2] + continue + elif not r: + t = "delete request failed: %r %s" + raise Exception(t % (r, r.text)) + break + locs = locs[len(req) :] if isdir: continue