From 90555a4ceaf77bcba6980275e424c0ba66b8d382 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 3 Aug 2022 21:06:10 +0200 Subject: [PATCH] clean-shutdown while hashing huge files --- copyparty/httpsrv.py | 2 +- copyparty/tcpsrv.py | 3 ++- copyparty/up2k.py | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index a6923e9d..5ae5dcb8 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -165,7 +165,7 @@ class HttpSrv(object): """listens on a shared tcp server""" ip, port = srv_sck.getsockname() fno = srv_sck.fileno() - msg = "subscribed @ {}:{} f{}".format(ip, port, fno) + msg = "subscribed @ {}:{} f{} p{}".format(ip, port, fno, os.getpid()) self.log(self.name, msg) def fun() -> None: diff --git a/copyparty/tcpsrv.py b/copyparty/tcpsrv.py index ae4c5f86..4badc02e 100644 --- a/copyparty/tcpsrv.py +++ b/copyparty/tcpsrv.py @@ -1,6 +1,7 @@ # coding: utf-8 from __future__ import print_function, unicode_literals +import os import re import socket import sys @@ -128,7 +129,7 @@ class TcpSrv(object): srv.listen(self.args.nc) ip, port = srv.getsockname() fno = srv.fileno() - msg = "listening @ {}:{} f{}".format(ip, port, fno) + msg = "listening @ {}:{} f{} p{}".format(ip, port, fno, os.getpid()) self.log("tcpsrv", msg) if self.args.q: print(msg) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index c3b19ae0..eabbe526 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -209,7 +209,8 @@ class Up2k(object): def _unblock(self) -> None: if self.blocked is not None: self.blocked = None - self.log("uploads are now possible", 2) + if not self.stop: + self.log("uploads are now possible", 2) def get_state(self) -> str: mtpq: Union[int, str] = 0 @@ -822,6 +823,9 @@ class Up2k(object): self.log("hash: {} @ [{}]".format(repr(ex), abspath)) continue + if not hashes: + return -1 + wark = up2k_wark_from_hashlist(self.salt, sz, hashes) self.db_add(db.c, wark, rd, fn, lmod, sz, "", 0) @@ -1035,6 +1039,9 @@ class Up2k(object): self.log("hash: {} @ [{}]".format(repr(ex), abspath)) continue + if not hashes: + return -1 + w2 = up2k_wark_from_hashlist(self.salt, sz2, hashes) if w == w2: @@ -2587,6 +2594,9 @@ class Up2k(object): ret = [] with open(fsenc(path), "rb", 512 * 1024) as f: while fsz > 0: + if self.stop: + return [] + if self.pp: mb = int(fsz / 1024 / 1024) self.pp.msg = "{}{} MB, {}".format(prefix, mb, path) @@ -2831,6 +2841,9 @@ class Up2k(object): self.log("hashing " + abspath) inf = bos.stat(abspath) hashes = self._hashlist_from_file(abspath) + if not hashes: + return + wark = up2k_wark_from_hashlist(self.salt, inf.st_size, hashes) with self.mutex: self.idx_wark(ptop, wark, rd, fn, inf.st_mtime, inf.st_size, ip, at)