smb: add mkdir/copy/rename/delete
This commit is contained in:
parent
4535a81617
commit
ff04b72f62
@ -59,7 +59,7 @@ try the **[read-only demo server](https://a.ocv.me/pub/demo/)** 👀 running fro
|
|||||||
* [qr-code](#qr-code) - print a qr-code [(screenshot)](https://user-images.githubusercontent.com/241032/194728533-6f00849b-c6ac-43c6-9359-83e454d11e00.png) for quick access
|
* [qr-code](#qr-code) - print a qr-code [(screenshot)](https://user-images.githubusercontent.com/241032/194728533-6f00849b-c6ac-43c6-9359-83e454d11e00.png) for quick access
|
||||||
* [ftp server](#ftp-server) - an FTP server can be started using `--ftp 3921`
|
* [ftp server](#ftp-server) - an FTP server can be started using `--ftp 3921`
|
||||||
* [webdav server](#webdav-server) - with read-write support
|
* [webdav server](#webdav-server) - with read-write support
|
||||||
* [smb server](#smb-server) - unsafe, not recommended for wan
|
* [smb server](#smb-server) - unsafe, slow, not recommended for wan
|
||||||
* [file indexing](#file-indexing) - enables dedup and music search ++
|
* [file indexing](#file-indexing) - enables dedup and music search ++
|
||||||
* [exclude-patterns](#exclude-patterns) - to save some time
|
* [exclude-patterns](#exclude-patterns) - to save some time
|
||||||
* [filesystem guards](#filesystem-guards) - avoid traversing into other filesystems
|
* [filesystem guards](#filesystem-guards) - avoid traversing into other filesystems
|
||||||
@ -755,7 +755,6 @@ some big warnings specific to SMB/CIFS, in decreasing importance:
|
|||||||
* shadowing (hiding the contents in subfolders by creating overlapping volumes) probably works as expected but no guarantees
|
* shadowing (hiding the contents in subfolders by creating overlapping volumes) probably works as expected but no guarantees
|
||||||
|
|
||||||
and some minor issues,
|
and some minor issues,
|
||||||
* files are not [indexed](#file-indexing) when uploaded through smb; please [schedule rescans](#periodic-rescan) as a workaround
|
|
||||||
* hot-reload of server config (`/?reload=cfg`) only works for volumes, not account passwords
|
* hot-reload of server config (`/?reload=cfg`) only works for volumes, not account passwords
|
||||||
* listens on the first `-i` interface only (default = 0.0.0.0 = all)
|
* listens on the first `-i` interface only (default = 0.0.0.0 = all)
|
||||||
* login doesn't work on winxp, but anonymous access is ok -- remove all accounts from copyparty config for that to work
|
* login doesn't work on winxp, but anonymous access is ok -- remove all accounts from copyparty config for that to work
|
||||||
|
@ -38,7 +38,7 @@ def mkdir(p: str, mode: int = 0o755) -> None:
|
|||||||
return os.mkdir(fsenc(p), mode)
|
return os.mkdir(fsenc(p), mode)
|
||||||
|
|
||||||
|
|
||||||
def open(p: str, *a, **ka) -> Any:
|
def open(p: str, *a, **ka) -> int:
|
||||||
return os.open(fsenc(p), *a, **ka)
|
return os.open(fsenc(p), *a, **ka)
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,8 +75,13 @@ class SMB(object):
|
|||||||
pass
|
pass
|
||||||
fos.close = self._close
|
fos.close = self._close
|
||||||
fos.listdir = self._listdir
|
fos.listdir = self._listdir
|
||||||
|
fos.mkdir = self._mkdir
|
||||||
fos.open = self._open
|
fos.open = self._open
|
||||||
|
fos.remove = self._unlink
|
||||||
|
fos.rename = self._rename
|
||||||
fos.stat = self._stat
|
fos.stat = self._stat
|
||||||
|
fos.unlink = self._unlink
|
||||||
|
fos.utime = self._utime
|
||||||
smbserver.os = fos
|
smbserver.os = fos
|
||||||
|
|
||||||
# ...and smbserver.os.path
|
# ...and smbserver.os.path
|
||||||
@ -160,7 +165,7 @@ class SMB(object):
|
|||||||
if not readonly:
|
if not readonly:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
nf = len(self.files)
|
nf = len(self.files)
|
||||||
if nf > 10:
|
if nf > 9000:
|
||||||
oldest = min([x[0] for x in self.files.values()])
|
oldest = min([x[0] for x in self.files.values()])
|
||||||
cutoff = oldest + (now - oldest) / 2
|
cutoff = oldest + (now - oldest) / 2
|
||||||
self.files = {k: v for k, v in self.files.items() if v[0] > cutoff}
|
self.files = {k: v for k, v in self.files.items() if v[0] > cutoff}
|
||||||
@ -188,9 +193,28 @@ class SMB(object):
|
|||||||
time.time(),
|
time.time(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _rename(self, vp1: str, vp2: str) -> None:
|
||||||
|
vp1 = vp1.lstrip("/")
|
||||||
|
vp2 = vp2.lstrip("/")
|
||||||
|
ap2 = self._v2a("rename", vp2, vp1)[1]
|
||||||
|
self.hub.up2k.handle_mv(LEELOO_DALLAS, vp1, vp2)
|
||||||
|
bos.makedirs(ap2, exist_ok=True)
|
||||||
|
|
||||||
|
def _mkdir(self, vpath: str) -> None:
|
||||||
|
return bos.mkdir(self._v2a("mkdir", vpath)[1])
|
||||||
|
|
||||||
def _stat(self, vpath: str, *a: Any, **ka: Any) -> os.stat_result:
|
def _stat(self, vpath: str, *a: Any, **ka: Any) -> os.stat_result:
|
||||||
return bos.stat(self._v2a("stat", vpath, *a)[1], *a, **ka)
|
return bos.stat(self._v2a("stat", vpath, *a)[1], *a, **ka)
|
||||||
|
|
||||||
|
def _unlink(self, vpath: str) -> None:
|
||||||
|
# return bos.unlink(self._v2a("stat", vpath, *a)[1])
|
||||||
|
logging.info("delete %s", vpath)
|
||||||
|
vp = vpath.lstrip("/")
|
||||||
|
self.hub.up2k.handle_rm(LEELOO_DALLAS, "1.7.6.2", [vp], [])
|
||||||
|
|
||||||
|
def _utime(self, vpath: str, times: tuple[float, float]) -> None:
|
||||||
|
return bos.utime(self._v2a("stat", vpath)[1], times)
|
||||||
|
|
||||||
def _p_exists(self, vpath: str) -> bool:
|
def _p_exists(self, vpath: str) -> bool:
|
||||||
try:
|
try:
|
||||||
bos.stat(self._v2a("p.exists", vpath)[1])
|
bos.stat(self._v2a("p.exists", vpath)[1])
|
||||||
@ -223,14 +247,10 @@ class SMB(object):
|
|||||||
smbserver.os.lchown = self._hook
|
smbserver.os.lchown = self._hook
|
||||||
smbserver.os.link = self._hook
|
smbserver.os.link = self._hook
|
||||||
smbserver.os.lstat = self._hook
|
smbserver.os.lstat = self._hook
|
||||||
smbserver.os.mkdir = self._hook
|
|
||||||
smbserver.os.remove = self._hook
|
|
||||||
smbserver.os.rename = self._hook
|
|
||||||
smbserver.os.replace = self._hook
|
smbserver.os.replace = self._hook
|
||||||
smbserver.os.scandir = self._hook
|
smbserver.os.scandir = self._hook
|
||||||
smbserver.os.symlink = self._hook
|
smbserver.os.symlink = self._hook
|
||||||
smbserver.os.truncate = self._hook
|
smbserver.os.truncate = self._hook
|
||||||
smbserver.os.unlink = self._hook
|
|
||||||
smbserver.os.walk = self._hook
|
smbserver.os.walk = self._hook
|
||||||
|
|
||||||
smbserver.os.path.abspath = self._hook
|
smbserver.os.path.abspath = self._hook
|
||||||
|
Loading…
Reference in New Issue
Block a user