Skip to content

Commit b5ad936

Browse files
committed
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
1 parent 4401de0 commit b5ad936

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

copyparty/up2k.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,8 +3755,11 @@ def _handle_rm(
37553755
cur = None
37563756
try:
37573757
ptop = dbv.realpath
3758+
xlink = bool(dbv.flags.get("xlink"))
37583759
cur, wark, _, _, _, _ = self._find_from_vpath(ptop, volpath)
3759-
self._forget_file(ptop, volpath, cur, wark, True, st.st_size)
3760+
self._forget_file(
3761+
ptop, volpath, cur, wark, True, st.st_size, xlink
3762+
)
37603763
finally:
37613764
if cur:
37623765
cur.connection.commit()
@@ -3980,13 +3983,15 @@ def _mv_file(
39803983
if c2 and c2 != c1:
39813984
self._copy_tags(c1, c2, w)
39823985

3986+
xlink = bool(svn.flags.get("xlink"))
3987+
39833988
with self.reg_mutex:
39843989
has_dupes = self._forget_file(
3985-
svn.realpath, srem, c1, w, is_xvol, fsize_ or fsize
3990+
svn.realpath, srem, c1, w, is_xvol, fsize_ or fsize, xlink
39863991
)
39873992

39883993
if not is_xvol:
3989-
has_dupes = self._relink(w, svn.realpath, srem, dabs)
3994+
has_dupes = self._relink(w, svn.realpath, srem, dabs, c1, xlink)
39903995

39913996
curs.add(c1)
39923997

@@ -4129,6 +4134,7 @@ def _forget_file(
41294134
wark: Optional[str],
41304135
drop_tags: bool,
41314136
sz: int,
4137+
xlink: bool,
41324138
) -> bool:
41334139
"""
41344140
mutex(main,reg) me
@@ -4140,7 +4146,7 @@ def _forget_file(
41404146
if wark and cur:
41414147
self.log("found {} in db".format(wark))
41424148
if drop_tags:
4143-
if self._relink(wark, ptop, vrem, ""):
4149+
if self._relink(wark, ptop, vrem, "", cur, xlink):
41444150
has_dupes = True
41454151
drop_tags = False
41464152

@@ -4172,7 +4178,15 @@ def _forget_file(
41724178

41734179
return has_dupes
41744180

4175-
def _relink(self, wark: str, sptop: str, srem: str, dabs: str) -> int:
4181+
def _relink(
4182+
self,
4183+
wark: str,
4184+
sptop: str,
4185+
srem: str,
4186+
dabs: str,
4187+
vcur: Optional["sqlite3.Cursor"],
4188+
xlink: bool,
4189+
) -> int:
41764190
"""
41774191
update symlinks from file at svn/srem to dabs (rename),
41784192
or to first remaining full if no dabs (delete)
@@ -4188,6 +4202,8 @@ def _relink(self, wark: str, sptop: str, srem: str, dabs: str) -> int:
41884202
argv = (wark[:16], wark)
41894203

41904204
for ptop, cur in self.cur.items():
4205+
if not xlink and cur and cur != vcur:
4206+
continue
41914207
for rd, fn in cur.execute(q, argv):
41924208
if rd.startswith("//") or fn.startswith("//"):
41934209
rd, fn = s3dec(rd, fn)

0 commit comments

Comments
 (0)