confine xlink behavior behind its volflag

symlinks between volumes will only be created if xlink is
enabled, so such symlinks should be ignored if xlink is
disabled, as they might originate from other software

this prevents accidental rewriting of non-dedup symlinks
This commit is contained in:
ed 2024-09-07 19:17:32 +00:00
parent 4401de0413
commit b5ad9369fe

View file

@ -3755,8 +3755,11 @@ class Up2k(object):
cur = None cur = None
try: try:
ptop = dbv.realpath ptop = dbv.realpath
xlink = bool(dbv.flags.get("xlink"))
cur, wark, _, _, _, _ = self._find_from_vpath(ptop, volpath) cur, wark, _, _, _, _ = self._find_from_vpath(ptop, volpath)
self._forget_file(ptop, volpath, cur, wark, True, st.st_size) self._forget_file(
ptop, volpath, cur, wark, True, st.st_size, xlink
)
finally: finally:
if cur: if cur:
cur.connection.commit() cur.connection.commit()
@ -3980,13 +3983,15 @@ class Up2k(object):
if c2 and c2 != c1: if c2 and c2 != c1:
self._copy_tags(c1, c2, w) self._copy_tags(c1, c2, w)
xlink = bool(svn.flags.get("xlink"))
with self.reg_mutex: with self.reg_mutex:
has_dupes = self._forget_file( has_dupes = self._forget_file(
svn.realpath, srem, c1, w, is_xvol, fsize_ or fsize svn.realpath, srem, c1, w, is_xvol, fsize_ or fsize, xlink
) )
if not is_xvol: if not is_xvol:
has_dupes = self._relink(w, svn.realpath, srem, dabs) has_dupes = self._relink(w, svn.realpath, srem, dabs, c1, xlink)
curs.add(c1) curs.add(c1)
@ -4129,6 +4134,7 @@ class Up2k(object):
wark: Optional[str], wark: Optional[str],
drop_tags: bool, drop_tags: bool,
sz: int, sz: int,
xlink: bool,
) -> bool: ) -> bool:
""" """
mutex(main,reg) me mutex(main,reg) me
@ -4140,7 +4146,7 @@ class Up2k(object):
if wark and cur: if wark and cur:
self.log("found {} in db".format(wark)) self.log("found {} in db".format(wark))
if drop_tags: if drop_tags:
if self._relink(wark, ptop, vrem, ""): if self._relink(wark, ptop, vrem, "", cur, xlink):
has_dupes = True has_dupes = True
drop_tags = False drop_tags = False
@ -4172,7 +4178,15 @@ class Up2k(object):
return has_dupes return has_dupes
def _relink(self, wark: str, sptop: str, srem: str, dabs: str) -> int: def _relink(
self,
wark: str,
sptop: str,
srem: str,
dabs: str,
vcur: Optional["sqlite3.Cursor"],
xlink: bool,
) -> int:
""" """
update symlinks from file at svn/srem to dabs (rename), update symlinks from file at svn/srem to dabs (rename),
or to first remaining full if no dabs (delete) or to first remaining full if no dabs (delete)
@ -4188,6 +4202,8 @@ class Up2k(object):
argv = (wark[:16], wark) argv = (wark[:16], wark)
for ptop, cur in self.cur.items(): for ptop, cur in self.cur.items():
if not xlink and cur and cur != vcur:
continue
for rd, fn in cur.execute(q, argv): for rd, fn in cur.execute(q, argv):
if rd.startswith("//") or fn.startswith("//"): if rd.startswith("//") or fn.startswith("//"):
rd, fn = s3dec(rd, fn) rd, fn = s3dec(rd, fn)