only drop tags when its safe

This commit is contained in:
ed 2021-07-31 13:19:02 +02:00
parent 08f4695283
commit a918cc67eb

View file

@ -1405,7 +1405,7 @@ class Up2k(object):
try: try:
ptop = dbv.realpath ptop = dbv.realpath
cur, wark, _, _, _, _ = self._find_from_vpath(ptop, volpath) cur, wark, _, _, _, _ = self._find_from_vpath(ptop, volpath)
self._forget_file(ptop, volpath, cur, wark) self._forget_file(ptop, volpath, cur, wark, True)
finally: finally:
cur.connection.commit() cur.connection.commit()
@ -1491,10 +1491,10 @@ class Up2k(object):
fsize = st.st_size fsize = st.st_size
if w: if w:
if c2: if c2 and c2 != c1:
self._copy_tags(c1, c2, w) self._copy_tags(c1, c2, w)
self._forget_file(svn.realpath, srem, c1, w) self._forget_file(svn.realpath, srem, c1, w, c1 != c2)
self._relink(w, svn.realpath, srem, dabs) self._relink(w, svn.realpath, srem, dabs)
c1.connection.commit() c1.connection.commit()
@ -1535,14 +1535,16 @@ class Up2k(object):
return cur, wark, ftime, fsize, ip, at return cur, wark, ftime, fsize, ip, at
return cur, None, None, None, None, None return cur, None, None, None, None, None
def _forget_file(self, ptop, vrem, cur, wark): def _forget_file(self, ptop, vrem, cur, wark, drop_tags):
"""forgets file in db, fixes symlinks, does not delete""" """forgets file in db, fixes symlinks, does not delete"""
srd, sfn = vsplit(vrem) srd, sfn = vsplit(vrem)
self.log("forgetting {}".format(vrem)) self.log("forgetting {}".format(vrem))
if wark: if wark:
self.log("found {} in db".format(wark)) self.log("found {} in db".format(wark))
self._relink(wark, ptop, vrem, None) if self._relink(wark, ptop, vrem, None):
drop_tags = False
if drop_tags:
q = "delete from mt where w=?" q = "delete from mt where w=?"
cur.execute(q, (wark[:16],)) cur.execute(q, (wark[:16],))
self.db_rm(cur, srd, sfn) self.db_rm(cur, srd, sfn)
@ -1581,7 +1583,7 @@ class Up2k(object):
self.log("found {} dupe: [{}] {}".format(wark, ptop, dvrem)) self.log("found {} dupe: [{}] {}".format(wark, ptop, dvrem))
if not dupes: if not dupes:
return return 0
full = {} full = {}
links = {} links = {}
@ -1618,6 +1620,8 @@ class Up2k(object):
self._symlink(dabs, alink, False) self._symlink(dabs, alink, False)
return len(full) + len(links)
def _get_wark(self, cj): def _get_wark(self, cj):
if len(cj["name"]) > 1024 or len(cj["hash"]) > 512 * 1024: # 16TiB if len(cj["name"]) > 1024 or len(cj["hash"]) > 512 * 1024: # 16TiB
raise Pebkac(400, "name or numchunks not according to spec") raise Pebkac(400, "name or numchunks not according to spec")