clean-shutdown while hashing huge files

This commit is contained in:
ed 2022-08-03 21:06:10 +02:00
parent 56a62db591
commit 90555a4cea
3 changed files with 17 additions and 3 deletions

View file

@ -165,7 +165,7 @@ class HttpSrv(object):
"""listens on a shared tcp server""" """listens on a shared tcp server"""
ip, port = srv_sck.getsockname() ip, port = srv_sck.getsockname()
fno = srv_sck.fileno() 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) self.log(self.name, msg)
def fun() -> None: def fun() -> None:

View file

@ -1,6 +1,7 @@
# coding: utf-8 # coding: utf-8
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import os
import re import re
import socket import socket
import sys import sys
@ -128,7 +129,7 @@ class TcpSrv(object):
srv.listen(self.args.nc) srv.listen(self.args.nc)
ip, port = srv.getsockname() ip, port = srv.getsockname()
fno = srv.fileno() fno = srv.fileno()
msg = "listening @ {}:{} f{}".format(ip, port, fno) msg = "listening @ {}:{} f{} p{}".format(ip, port, fno, os.getpid())
self.log("tcpsrv", msg) self.log("tcpsrv", msg)
if self.args.q: if self.args.q:
print(msg) print(msg)

View file

@ -209,7 +209,8 @@ class Up2k(object):
def _unblock(self) -> None: def _unblock(self) -> None:
if self.blocked is not None: if self.blocked is not None:
self.blocked = 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: def get_state(self) -> str:
mtpq: Union[int, str] = 0 mtpq: Union[int, str] = 0
@ -822,6 +823,9 @@ class Up2k(object):
self.log("hash: {} @ [{}]".format(repr(ex), abspath)) self.log("hash: {} @ [{}]".format(repr(ex), abspath))
continue continue
if not hashes:
return -1
wark = up2k_wark_from_hashlist(self.salt, sz, hashes) wark = up2k_wark_from_hashlist(self.salt, sz, hashes)
self.db_add(db.c, wark, rd, fn, lmod, sz, "", 0) 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)) self.log("hash: {} @ [{}]".format(repr(ex), abspath))
continue continue
if not hashes:
return -1
w2 = up2k_wark_from_hashlist(self.salt, sz2, hashes) w2 = up2k_wark_from_hashlist(self.salt, sz2, hashes)
if w == w2: if w == w2:
@ -2587,6 +2594,9 @@ class Up2k(object):
ret = [] ret = []
with open(fsenc(path), "rb", 512 * 1024) as f: with open(fsenc(path), "rb", 512 * 1024) as f:
while fsz > 0: while fsz > 0:
if self.stop:
return []
if self.pp: if self.pp:
mb = int(fsz / 1024 / 1024) mb = int(fsz / 1024 / 1024)
self.pp.msg = "{}{} MB, {}".format(prefix, mb, path) self.pp.msg = "{}{} MB, {}".format(prefix, mb, path)
@ -2831,6 +2841,9 @@ class Up2k(object):
self.log("hashing " + abspath) self.log("hashing " + abspath)
inf = bos.stat(abspath) inf = bos.stat(abspath)
hashes = self._hashlist_from_file(abspath) hashes = self._hashlist_from_file(abspath)
if not hashes:
return
wark = up2k_wark_from_hashlist(self.salt, inf.st_size, hashes) wark = up2k_wark_from_hashlist(self.salt, inf.st_size, hashes)
with self.mutex: with self.mutex:
self.idx_wark(ptop, wark, rd, fn, inf.st_mtime, inf.st_size, ip, at) self.idx_wark(ptop, wark, rd, fn, inf.st_mtime, inf.st_size, ip, at)