mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
abort volume indexing on ^C
This commit is contained in:
parent
a3431512d8
commit
3683984c8d
|
@ -95,6 +95,7 @@ class Up2k(object):
|
||||||
self.r_hash = re.compile("^[0-9a-zA-Z_-]{44}$")
|
self.r_hash = re.compile("^[0-9a-zA-Z_-]{44}$")
|
||||||
|
|
||||||
self.gid = 0
|
self.gid = 0
|
||||||
|
self.stop = False
|
||||||
self.mutex = threading.Lock()
|
self.mutex = threading.Lock()
|
||||||
self.pp: Optional[ProgressPrinter] = None
|
self.pp: Optional[ProgressPrinter] = None
|
||||||
self.rescan_cond = threading.Condition()
|
self.rescan_cond = threading.Condition()
|
||||||
|
@ -415,6 +416,9 @@ class Up2k(object):
|
||||||
|
|
||||||
# e2ds(a) volumes first
|
# e2ds(a) volumes first
|
||||||
for vol in vols:
|
for vol in vols:
|
||||||
|
if self.stop:
|
||||||
|
break
|
||||||
|
|
||||||
en: set[str] = set()
|
en: set[str] = set()
|
||||||
if "mte" in vol.flags:
|
if "mte" in vol.flags:
|
||||||
en = set(vol.flags["mte"].split(","))
|
en = set(vol.flags["mte"].split(","))
|
||||||
|
@ -440,6 +444,9 @@ class Up2k(object):
|
||||||
# open the rest + do any e2ts(a)
|
# open the rest + do any e2ts(a)
|
||||||
needed_mutagen = False
|
needed_mutagen = False
|
||||||
for vol in vols:
|
for vol in vols:
|
||||||
|
if self.stop:
|
||||||
|
break
|
||||||
|
|
||||||
if "e2ts" not in vol.flags:
|
if "e2ts" not in vol.flags:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -464,6 +471,9 @@ class Up2k(object):
|
||||||
cur.connection.commit()
|
cur.connection.commit()
|
||||||
cur.execute("vacuum")
|
cur.execute("vacuum")
|
||||||
|
|
||||||
|
if self.stop:
|
||||||
|
return False
|
||||||
|
|
||||||
self.pp.end = True
|
self.pp.end = True
|
||||||
|
|
||||||
msg = "{} volumes in {:.2f} sec"
|
msg = "{} volumes in {:.2f} sec"
|
||||||
|
@ -645,6 +655,9 @@ class Up2k(object):
|
||||||
gl = sorted(g)
|
gl = sorted(g)
|
||||||
inames = {x[0]: 1 for x in gl}
|
inames = {x[0]: 1 for x in gl}
|
||||||
for iname, inf in gl:
|
for iname, inf in gl:
|
||||||
|
if self.stop:
|
||||||
|
return -1
|
||||||
|
|
||||||
abspath = os.path.join(cdir, iname)
|
abspath = os.path.join(cdir, iname)
|
||||||
if rei and rei.search(abspath):
|
if rei and rei.search(abspath):
|
||||||
continue
|
continue
|
||||||
|
@ -740,6 +753,9 @@ class Up2k(object):
|
||||||
db.n = 0
|
db.n = 0
|
||||||
db.t = time.time()
|
db.t = time.time()
|
||||||
|
|
||||||
|
if self.stop:
|
||||||
|
return -1
|
||||||
|
|
||||||
# drop missing files
|
# drop missing files
|
||||||
rd = cdir[len(top) + 1 :].strip("/")
|
rd = cdir[len(top) + 1 :].strip("/")
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
|
@ -866,6 +882,9 @@ class Up2k(object):
|
||||||
c3 = conn.cursor()
|
c3 = conn.cursor()
|
||||||
n_left = cur.execute("select count(w) from up").fetchone()[0]
|
n_left = cur.execute("select count(w) from up").fetchone()[0]
|
||||||
for w, rd, fn in cur.execute("select w, rd, fn from up order by rd, fn"):
|
for w, rd, fn in cur.execute("select w, rd, fn from up order by rd, fn"):
|
||||||
|
if self.stop:
|
||||||
|
return -1, -1, False
|
||||||
|
|
||||||
n_left -= 1
|
n_left -= 1
|
||||||
q = "select w from mt where w = ?"
|
q = "select w from mt where w = ?"
|
||||||
if c2.execute(q, (w[:16],)).fetchone():
|
if c2.execute(q, (w[:16],)).fetchone():
|
||||||
|
@ -2466,6 +2485,7 @@ class Up2k(object):
|
||||||
# self.log("hashq {} push {}/{}/{}".format(self.n_hashq, ptop, rd, fn))
|
# self.log("hashq {} push {}/{}/{}".format(self.n_hashq, ptop, rd, fn))
|
||||||
|
|
||||||
def shutdown(self) -> None:
|
def shutdown(self) -> None:
|
||||||
|
self.stop = True
|
||||||
self.log("writing snapshot")
|
self.log("writing snapshot")
|
||||||
self.do_snapshot()
|
self.do_snapshot()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue