improve dotfile handling; closes #126

when deleting a folder, any dotfiles/folders within would only
be deleted if the user had the dot-permission to see dotfiles;
this gave the confusing behavior of not removing the "empty"
folders after deleting them

fix this to only require the delete-permission, and always
delete the entire folder, including any dotfiles within

similar behavior would also apply to moves, renames, and copies;

fix moves and renames to only require the move-permission in
the source volume; dotfiles will now always be included,
regardless of whether the user does (or does not) have the
dot-permission in either the source and/or destination volumes

copying folders now also behaves more intuitively: if the user has
the dot-permission in the target volume, then dotfiles will only be
included from source folders where the user also has the dot-perm,
to prevent the user from seeing intentionally hidden files/folders
This commit is contained in:
ed 2024-12-17 22:47:34 +01:00
parent 01a3eb29cb
commit 4c4e48bab7
2 changed files with 13 additions and 8 deletions

View file

@ -658,7 +658,7 @@ class VFS(object):
seen: list[str],
uname: str,
permsets: list[list[bool]],
wantdots: bool,
wantdots: int,
scandir: bool,
lstat: bool,
subvols: bool = True,
@ -706,7 +706,7 @@ class VFS(object):
rm1.append(le)
_ = [vfs_ls.remove(x) for x in rm1] # type: ignore
dots_ok = wantdots and uname in dbv.axs.udot
dots_ok = wantdots and (wantdots == 2 or uname in dbv.axs.udot)
if not dots_ok:
vfs_ls = [x for x in vfs_ls if "/." not in "/" + x[0]]
@ -760,7 +760,7 @@ class VFS(object):
# if single folder: the folder itself is the top-level item
folder = "" if flt or not wrap else (vpath.split("/")[-1].lstrip(".") or "top")
g = self.walk(folder, vrem, [], uname, [[True, False]], True, scandir, False)
g = self.walk(folder, vrem, [], uname, [[True, False]], 1, scandir, False)
for _, _, vpath, apath, files, rd, vd in g:
if flt:
files = [x for x in files if x[0] in flt]
@ -2696,7 +2696,7 @@ class AuthSrv(object):
[],
u,
[[True, False]],
True,
1,
not self.args.no_scandir,
False,
False,

View file

@ -3977,7 +3977,7 @@ class Up2k(object):
if is_dir:
# note: deletion inside shares would require a rewrite here;
# shares necessitate get_dbv which is incompatible with walk
g = vn0.walk("", rem0, [], uname, permsets, True, scandir, True)
g = vn0.walk("", rem0, [], uname, permsets, 2, scandir, True)
if unpost:
raise Pebkac(400, "cannot unpost folders")
elif stat.S_ISLNK(st.st_mode) or stat.S_ISREG(st.st_mode):
@ -4090,6 +4090,7 @@ class Up2k(object):
raise Pebkac(400, "cp: cannot copy parent into subfolder")
svn, srem = self.vfs.get(svp, uname, True, False)
dvn, drem = self.vfs.get(dvp, uname, False, True)
svn_dbv, _ = svn.get_dbv(srem)
sabs = svn.canonical(srem, False)
curs: set["sqlite3.Cursor"] = set()
@ -4112,8 +4113,12 @@ class Up2k(object):
permsets = [[True, False]]
scandir = not self.args.no_scandir
# if user can see dotfiles in target volume, only include
# dots from source vols where user also has the dot perm
dots = 1 if uname in dvn.axs.udot else 2
# don't use svn_dbv; would skip subvols due to _ls `if not rem:`
g = svn.walk("", srem, [], uname, permsets, True, scandir, True)
g = svn.walk("", srem, [], uname, permsets, dots, scandir, True)
with self.mutex:
try:
for dbv, vrem, _, atop, files, rd, vd in g:
@ -4325,13 +4330,13 @@ class Up2k(object):
scandir = not self.args.no_scandir
# following symlinks is too scary
g = svn.walk("", srem, [], uname, permsets, True, scandir, True)
g = svn.walk("", srem, [], uname, permsets, 2, scandir, True)
for dbv, vrem, _, atop, files, rd, vd in g:
if dbv != jail:
# fail early (prevent partial moves)
raise Pebkac(400, "mv: source folder contains other volumes")
g = svn.walk("", srem, [], uname, permsets, True, scandir, True)
g = svn.walk("", srem, [], uname, permsets, 2, scandir, True)
with self.mutex:
try:
for dbv, vrem, _, atop, files, rd, vd in g: