diff --git a/__pycache__/engine.cpython-315.pyc b/__pycache__/engine.cpython-315.pyc new file mode 100644 index 0000000..df4546e Binary files /dev/null and b/__pycache__/engine.cpython-315.pyc differ diff --git a/app.py b/app.py index e235c98..439d537 100644 --- a/app.py +++ b/app.py @@ -721,15 +721,38 @@ def fm_delete(paths): if p.count("/") < 2: raise E.PipeError("Por seguridad no borro carpetas de primer nivel (%s)" % p) + def free_now(): + try: + return int(bf._req("GET", "/api/fs/stat", {"path": paths[0].rsplit("/", 1)[0] or "/"}, + timeout=8).get("availableBytes") or 0) + except Exception: + return None + def work(): + start = free_now() + last = {"t": 0.0} + + def tick(): + # Borrar un juego grande tarda: ensenamos lo que se va liberando para que se vea que avanza + if start is None or time.time() - last["t"] < 3: + return + last["t"] = time.time() + now = free_now() + if now is not None: + with LOCK: + FMOP["bytes_done"] = max(0, now - start) + FMOP["message"] = "" for i, p in enumerate(paths): if FM_CANCEL.is_set(): raise E.Cancelled() with LOCK: FMOP.update(current=p, items_done=i) - bf.delete(p, FM_CANCEL) + bf.delete(p, FM_CANCEL, on_tick=tick) + tick() with LOCK: FMOP["items_done"] = len(paths) + if FMOP["bytes_done"]: + FMOP["message"] = "Hecho: liberados %s" % human(FMOP["bytes_done"]) _fm_start("delete", len(paths), work) diff --git a/engine.py b/engine.py index c237072..e3a220e 100644 --- a/engine.py +++ b/engine.py @@ -1257,11 +1257,16 @@ class BFpilot: except Exception: return "" - def wait_job(self, cancel, timeout=3600): + def wait_job(self, cancel, timeout=3600, on_tick=None): t0 = time.time() while time.time() - t0 < timeout: if cancel is not None and cancel.is_set(): raise Cancelled() + if on_tick is not None: + try: + on_tick() + except Exception: + pass j = self._req("GET", "/api/fs/job/status") if not j.get("busy"): if j.get("error"): @@ -1270,7 +1275,7 @@ class BFpilot: time.sleep(1) raise PipeError("BFpilot tarda demasiado") - def delete(self, path, cancel=None): + def delete(self, path, cancel=None, on_tick=None): for _ in range(60): try: self._req("POST", "/api/fs/delete", form={"path": path, "recursive": "1"}) @@ -1282,7 +1287,7 @@ class BFpilot: if "No such file" in str(e) or "not found" in str(e).lower(): return raise - self.wait_job(cancel) + self.wait_job(cancel, timeout=4 * 3600, on_tick=on_tick) def du(self, path, timeout=20): """Tamano total de una carpeta (o archivo), o None.""" diff --git a/web/index.html b/web/index.html index 90f71ba..6e2521b 100644 --- a/web/index.html +++ b/web/index.html @@ -404,7 +404,7 @@ tr:hover .rowact{opacity:1}