From 195eb5399584ac07e25124e0c33fba8ed6f11e02 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 7 Dec 2022 23:09:40 +0000 Subject: [PATCH] merge wal on shutdown --- copyparty/httpconn.py | 3 +++ copyparty/u2idx.py | 7 +++++++ copyparty/up2k.py | 18 ++++++++++++++++++ tests/util.py | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index d7a29cb0..003897bd 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -83,6 +83,9 @@ class HttpConn(object): except: pass + if self.u2idx: + self.u2idx.shutdown() + def set_rproxy(self, ip: Optional[str] = None) -> str: if ip is None: color = 36 diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index 2c357bba..343950c4 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -60,6 +60,13 @@ class U2idx(object): def log(self, msg: str, c: Union[int, str] = 0) -> None: self.log_func("u2idx", msg, c) + def shutdown(self) -> None: + for v in self.cur.values(): + try: + v.close() + except: + pass + def fsearch( self, vols: list[tuple[str, str, dict[str, Any]]], body: dict[str, Any] ) -> list[dict[str, Any]]: diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 868db520..8a3ed288 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -181,6 +181,12 @@ class Up2k(object): all_vols = self.asrv.vfs.all_vols have_e2d = self.init_indexes(all_vols, []) + if self.stop: + if self.pp: + self.pp.end = True + self.pp = None + return + if not self.pp and self.args.exit == "idx": return self.hub.sigterm() @@ -3197,6 +3203,18 @@ class Up2k(object): self.log("writing snapshot") self.do_snapshot() + t0 = time.time() + while self.pp: + time.sleep(0.1) + if time.time() - t0 > 2: + break + + for cur in self.cur.values(): + try: + cur.close() + except: + pass + def up2k_chunksize(filesize: int) -> int: chunksize = 1024 * 1024 diff --git a/tests/util.py b/tests/util.py index 4c38635e..1a6c6f40 100644 --- a/tests/util.py +++ b/tests/util.py @@ -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_thumb no_vthumb 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_sync no_thumb no_vthumb no_wal 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"