Skip to content

Commit

Permalink
confine xlink behavior behind its volflag
Browse files Browse the repository at this point in the history
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
  • Loading branch information
9001 committed Sep 7, 2024
1 parent 4401de0 commit b5ad936
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions copyparty/up2k.py
Original file line number Diff line number Diff line change
Expand Up @@ -3755,8 +3755,11 @@ def _handle_rm(
cur = None
try:
ptop = dbv.realpath
xlink = bool(dbv.flags.get("xlink"))
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:
if cur:
cur.connection.commit()
Expand Down Expand Up @@ -3980,13 +3983,15 @@ def _mv_file(
if c2 and c2 != c1:
self._copy_tags(c1, c2, w)

xlink = bool(svn.flags.get("xlink"))

with self.reg_mutex:
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:
has_dupes = self._relink(w, svn.realpath, srem, dabs)
has_dupes = self._relink(w, svn.realpath, srem, dabs, c1, xlink)

curs.add(c1)

Expand Down Expand Up @@ -4129,6 +4134,7 @@ def _forget_file(
wark: Optional[str],
drop_tags: bool,
sz: int,
xlink: bool,
) -> bool:
"""
mutex(main,reg) me
Expand All @@ -4140,7 +4146,7 @@ def _forget_file(
if wark and cur:
self.log("found {} in db".format(wark))
if drop_tags:
if self._relink(wark, ptop, vrem, ""):
if self._relink(wark, ptop, vrem, "", cur, xlink):
has_dupes = True
drop_tags = False

Expand Down Expand Up @@ -4172,7 +4178,15 @@ def _forget_file(

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),
or to first remaining full if no dabs (delete)
Expand All @@ -4188,6 +4202,8 @@ def _relink(self, wark: str, sptop: str, srem: str, dabs: str) -> int:
argv = (wark[:16], wark)

for ptop, cur in self.cur.items():
if not xlink and cur and cur != vcur:
continue
for rd, fn in cur.execute(q, argv):
if rd.startswith("//") or fn.startswith("//"):
rd, fn = s3dec(rd, fn)
Expand Down

0 comments on commit b5ad936

Please sign in to comment.