mirror of
https://github.com/9001/copyparty.git
synced 2025-10-06 12:00:00 +02:00
vfs ls
This commit is contained in:
parent
250d0bdf57
commit
df276b6a84
3 changed files with 160 additions and 21 deletions
|
@ -2,7 +2,7 @@
|
|||
# coding: utf-8
|
||||
from __future__ import print_function
|
||||
|
||||
import pprint
|
||||
import os
|
||||
import threading
|
||||
|
||||
from .__init__ import *
|
||||
|
@ -30,14 +30,14 @@ class VFS(object):
|
|||
# exists; do not manipulate permissions
|
||||
return self.nodes[name].add(src, dst)
|
||||
|
||||
n = VFS(
|
||||
vn = VFS(
|
||||
"{}/{}".format(self.realpath, name),
|
||||
"{}/{}".format(self.vpath, name).lstrip("/"),
|
||||
self.uread,
|
||||
self.uwrite,
|
||||
)
|
||||
self.nodes[name] = n
|
||||
return n.add(src, dst)
|
||||
self.nodes[name] = vn
|
||||
return vn.add(src, dst)
|
||||
|
||||
if dst in self.nodes:
|
||||
# leaf exists; return as-is
|
||||
|
@ -45,9 +45,76 @@ class VFS(object):
|
|||
|
||||
# leaf does not exist; create and keep permissions blank
|
||||
vp = "{}/{}".format(self.vpath, dst).lstrip("/")
|
||||
n = VFS(src, vp)
|
||||
self.nodes[dst] = n
|
||||
return n
|
||||
vn = VFS(src, vp)
|
||||
self.nodes[dst] = vn
|
||||
return vn
|
||||
|
||||
def undot(self, path):
|
||||
ret = []
|
||||
for node in path.split("/"):
|
||||
if node in ["", "."]:
|
||||
continue
|
||||
|
||||
if node == "..":
|
||||
if ret:
|
||||
ret.pop()
|
||||
continue
|
||||
|
||||
ret.append(node)
|
||||
|
||||
return "/".join(ret)
|
||||
|
||||
def _find(self, vpath):
|
||||
"""return [vfs,remainder]"""
|
||||
vpath = self.undot(vpath)
|
||||
if vpath == "":
|
||||
return [self, ""]
|
||||
|
||||
if "/" in vpath:
|
||||
name, rem = vpath.split("/", 1)
|
||||
else:
|
||||
name = vpath
|
||||
rem = ""
|
||||
|
||||
if name in self.nodes:
|
||||
return self.nodes[name]._find(rem)
|
||||
|
||||
return [self, vpath]
|
||||
|
||||
def ls(self, vpath, user):
|
||||
"""return user-readable [virt,real] items at vpath"""
|
||||
vn, rem = self._find(vpath)
|
||||
|
||||
if user not in vn.uread:
|
||||
return [[], []]
|
||||
|
||||
rp = vn.realpath
|
||||
if rem:
|
||||
rp += "/" + rem
|
||||
|
||||
real = os.listdir(rp)
|
||||
real.sort()
|
||||
if rem:
|
||||
virt_vis = []
|
||||
else:
|
||||
virt_all = [] # all nodes that exist
|
||||
virt_vis = [] # nodes readable by user
|
||||
for name, vn2 in sorted(vn.nodes.items()):
|
||||
virt_all.append(name)
|
||||
if user in vn2.uread:
|
||||
virt_vis.append(name)
|
||||
|
||||
for name in virt_all:
|
||||
try:
|
||||
real.remove(name)
|
||||
except:
|
||||
pass
|
||||
|
||||
absreal = []
|
||||
for p in real:
|
||||
absreal.append("{}/{}".format(rp, p).replace("//", "/"))
|
||||
|
||||
return [absreal, virt_vis]
|
||||
|
||||
|
||||
class AuthSrv(object):
|
||||
|
@ -136,4 +203,5 @@ class AuthSrv(object):
|
|||
self.user = user
|
||||
self.iuser = self.invert(user)
|
||||
|
||||
# import pprint
|
||||
# pprint.pprint({"usr": user, "rd": mread, "wr": mwrite, "mnt": mount})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue