mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
cheaper file deletion
This commit is contained in:
parent
bd2d88c96e
commit
c6c31702c2
|
@ -1,6 +1,8 @@
|
||||||
// way more specific example --
|
// way more specific example --
|
||||||
// assumes all files dropped into the uploader have a youtube-id somewhere in the filename,
|
// assumes all files dropped into the uploader have a youtube-id somewhere in the filename,
|
||||||
// locates the youtube-ids and passes them to an API which returns a list of IDS which should be uploaded
|
// locates the youtube-ids and passes them to an API which returns a list of IDS which should be uploaded
|
||||||
|
//
|
||||||
|
// assumes copyparty is behind nginx as /ytq is a standalone service which must be rproxied in place
|
||||||
|
|
||||||
function up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
function up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
var filenames = [],
|
var filenames = [],
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import re
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from .__init__ import ANYWIN, MACOS
|
from .__init__ import ANYWIN, MACOS
|
||||||
|
|
|
@ -35,6 +35,7 @@ from .util import (
|
||||||
quotep,
|
quotep,
|
||||||
ren_open,
|
ren_open,
|
||||||
rmdirs,
|
rmdirs,
|
||||||
|
rmdirs_up,
|
||||||
s2hms,
|
s2hms,
|
||||||
s3dec,
|
s3dec,
|
||||||
s3enc,
|
s3enc,
|
||||||
|
@ -1857,11 +1858,12 @@ class Up2k(object):
|
||||||
adir, fn = os.path.split(atop)
|
adir, fn = os.path.split(atop)
|
||||||
try:
|
try:
|
||||||
st = bos.lstat(atop)
|
st = bos.lstat(atop)
|
||||||
|
is_dir = stat.S_ISDIR(st.st_mode)
|
||||||
except:
|
except:
|
||||||
raise Pebkac(400, "file not found on disk (already deleted?)")
|
raise Pebkac(400, "file not found on disk (already deleted?)")
|
||||||
|
|
||||||
scandir = not self.args.no_scandir
|
scandir = not self.args.no_scandir
|
||||||
if stat.S_ISDIR(st.st_mode):
|
if is_dir:
|
||||||
g = vn.walk("", rem, [], uname, permsets, True, scandir, True)
|
g = vn.walk("", rem, [], uname, permsets, True, scandir, True)
|
||||||
if unpost:
|
if unpost:
|
||||||
raise Pebkac(400, "cannot unpost folders")
|
raise Pebkac(400, "cannot unpost folders")
|
||||||
|
@ -1896,8 +1898,14 @@ class Up2k(object):
|
||||||
|
|
||||||
bos.unlink(abspath)
|
bos.unlink(abspath)
|
||||||
|
|
||||||
rm = rmdirs(self.log_func, scandir, True, atop, 1)
|
ok: list[str] = []
|
||||||
return n_files, rm[0], rm[1]
|
ng: list[str] = []
|
||||||
|
if is_dir:
|
||||||
|
ok, ng = rmdirs(self.log_func, scandir, True, atop, 1)
|
||||||
|
|
||||||
|
ok2, ng2 = rmdirs_up(os.path.dirname(atop))
|
||||||
|
|
||||||
|
return n_files, ok + ok2, ng + ng2
|
||||||
|
|
||||||
def handle_mv(self, uname: str, svp: str, dvp: str) -> str:
|
def handle_mv(self, uname: str, svp: str, dvp: str) -> str:
|
||||||
svn, srem = self.asrv.vfs.get(svp, uname, True, False, True)
|
svn, srem = self.asrv.vfs.get(svp, uname, True, False, True)
|
||||||
|
@ -1939,6 +1947,7 @@ class Up2k(object):
|
||||||
self._mv_file(uname, svpf, dvpf)
|
self._mv_file(uname, svpf, dvpf)
|
||||||
|
|
||||||
rmdirs(self.log_func, scandir, True, sabs, 1)
|
rmdirs(self.log_func, scandir, True, sabs, 1)
|
||||||
|
rmdirs_up(os.path.dirname(sabs))
|
||||||
return "k"
|
return "k"
|
||||||
|
|
||||||
def _mv_file(self, uname: str, svp: str, dvp: str) -> str:
|
def _mv_file(self, uname: str, svp: str, dvp: str) -> str:
|
||||||
|
|
|
@ -1422,7 +1422,8 @@ def statdir(
|
||||||
def rmdirs(
|
def rmdirs(
|
||||||
logger: RootLogger, scandir: bool, lstat: bool, top: str, depth: int
|
logger: RootLogger, scandir: bool, lstat: bool, top: str, depth: int
|
||||||
) -> tuple[list[str], list[str]]:
|
) -> tuple[list[str], list[str]]:
|
||||||
if not os.path.exists(fsenc(top)) or not os.path.isdir(fsenc(top)):
|
"""rmdir all descendants, then self"""
|
||||||
|
if not os.path.isdir(fsenc(top)):
|
||||||
top = os.path.dirname(top)
|
top = os.path.dirname(top)
|
||||||
depth -= 1
|
depth -= 1
|
||||||
|
|
||||||
|
@ -1446,6 +1447,21 @@ def rmdirs(
|
||||||
return ok, ng
|
return ok, ng
|
||||||
|
|
||||||
|
|
||||||
|
def rmdirs_up(top: str) -> tuple[list[str], list[str]]:
|
||||||
|
"""rmdir on self, then all parents"""
|
||||||
|
try:
|
||||||
|
os.rmdir(fsenc(top))
|
||||||
|
except:
|
||||||
|
return [], [top]
|
||||||
|
|
||||||
|
par = os.path.dirname(top)
|
||||||
|
if not par:
|
||||||
|
return [top], []
|
||||||
|
|
||||||
|
ok, ng = rmdirs_up(par)
|
||||||
|
return [top] + ok, ng
|
||||||
|
|
||||||
|
|
||||||
def unescape_cookie(orig: str) -> str:
|
def unescape_cookie(orig: str) -> str:
|
||||||
# mw=idk; doot=qwe%2Crty%3Basd+fgh%2Bjkl%25zxc%26vbn # qwe,rty;asd fgh+jkl%zxc&vbn
|
# mw=idk; doot=qwe%2Crty%3Basd+fgh%2Bjkl%25zxc%26vbn # qwe,rty;asd fgh+jkl%zxc&vbn
|
||||||
ret = ""
|
ret = ""
|
||||||
|
@ -1802,7 +1818,6 @@ def termsize() -> tuple[int, int]:
|
||||||
def ioctl_GWINSZ(fd: int) -> Optional[tuple[int, int]]:
|
def ioctl_GWINSZ(fd: int) -> Optional[tuple[int, int]]:
|
||||||
try:
|
try:
|
||||||
import fcntl
|
import fcntl
|
||||||
import struct
|
|
||||||
import termios
|
import termios
|
||||||
|
|
||||||
cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, b"1234"))
|
cr = struct.unpack("hh", fcntl.ioctl(fd, termios.TIOCGWINSZ, b"1234"))
|
||||||
|
|
Loading…
Reference in a new issue