windows fixes
This commit is contained in:
parent
af59808611
commit
447ed5ab37
27
bin/up2k.py
27
bin/up2k.py
@ -3,14 +3,12 @@ from __future__ import print_function, unicode_literals
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
up2k.py: upload to copyparty
|
up2k.py: upload to copyparty
|
||||||
2022-12-11, v0.23, ed <irc.rizon.net>, MIT-Licensed
|
2022-12-12, v1.0, ed <irc.rizon.net>, MIT-Licensed
|
||||||
https://github.com/9001/copyparty/blob/hovudstraum/bin/up2k.py
|
https://github.com/9001/copyparty/blob/hovudstraum/bin/up2k.py
|
||||||
|
|
||||||
- dependencies: requests
|
- dependencies: requests
|
||||||
- supports python 2.6, 2.7, and 3.3 through 3.11
|
- supports python 2.6, 2.7, and 3.3 through 3.12
|
||||||
|
- if something breaks just try again and it'll autoresume
|
||||||
- almost zero error-handling
|
|
||||||
- but if something breaks just try again and it'll autoresume
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -375,14 +373,16 @@ def walkdirs(err, tops):
|
|||||||
"""recursive statdir for a list of tops, yields [top, relpath, stat]"""
|
"""recursive statdir for a list of tops, yields [top, relpath, stat]"""
|
||||||
sep = "{0}".format(os.sep).encode("ascii")
|
sep = "{0}".format(os.sep).encode("ascii")
|
||||||
for top in tops:
|
for top in tops:
|
||||||
|
isdir = os.path.isdir(top)
|
||||||
if top[-1:] == sep:
|
if top[-1:] == sep:
|
||||||
stop = top.rstrip(sep)
|
stop = top.rstrip(sep)
|
||||||
yield stop, b"", os.stat(stop)
|
yield stop, b"", os.stat(stop)
|
||||||
else:
|
else:
|
||||||
stop, dn = os.path.split(top)
|
stop, dn = os.path.split(top)
|
||||||
|
if isdir:
|
||||||
yield stop, dn, os.stat(stop)
|
yield stop, dn, os.stat(stop)
|
||||||
|
|
||||||
if os.path.isdir(top):
|
if isdir:
|
||||||
for ap, inf in walkdir(err, top, []):
|
for ap, inf in walkdir(err, top, []):
|
||||||
yield stop, ap[len(stop) :].lstrip(sep), inf
|
yield stop, ap[len(stop) :].lstrip(sep), inf
|
||||||
else:
|
else:
|
||||||
@ -784,7 +784,7 @@ class Ctl(object):
|
|||||||
isdir = stat.S_ISDIR(inf.st_mode)
|
isdir = stat.S_ISDIR(inf.st_mode)
|
||||||
if self.ar.z or self.ar.drd:
|
if self.ar.z or self.ar.drd:
|
||||||
rd = rel if isdir else os.path.dirname(rel)
|
rd = rel if isdir else os.path.dirname(rel)
|
||||||
srd = rd.decode("utf-8", "replace")
|
srd = rd.decode("utf-8", "replace").replace("\\", "/")
|
||||||
if prd != rd:
|
if prd != rd:
|
||||||
prd = rd
|
prd = rd
|
||||||
headers = {}
|
headers = {}
|
||||||
@ -801,8 +801,8 @@ class Ctl(object):
|
|||||||
for f in j["dirs"] + j["files"]:
|
for f in j["dirs"] + j["files"]:
|
||||||
rfn = f["href"].split("?")[0].rstrip("/")
|
rfn = f["href"].split("?")[0].rstrip("/")
|
||||||
ls[unquote(rfn.encode("utf-8", "replace"))] = f
|
ls[unquote(rfn.encode("utf-8", "replace"))] = f
|
||||||
except:
|
except Exception as ex:
|
||||||
print(" mkdir ~{0}".format(srd))
|
print(" mkdir ~{0} ({1})".format(srd, ex))
|
||||||
|
|
||||||
if self.ar.drd:
|
if self.ar.drd:
|
||||||
dp = os.path.join(top, rd)
|
dp = os.path.join(top, rd)
|
||||||
@ -987,7 +987,10 @@ source file/folder selection uses rsync syntax, meaning that:
|
|||||||
ap.add_argument("-a", metavar="PASSWORD", help="password")
|
ap.add_argument("-a", metavar="PASSWORD", help="password")
|
||||||
ap.add_argument("-s", action="store_true", help="file-search (disables upload)")
|
ap.add_argument("-s", action="store_true", help="file-search (disables upload)")
|
||||||
ap.add_argument("--ok", action="store_true", help="continue even if some local files are inaccessible")
|
ap.add_argument("--ok", action="store_true", help="continue even if some local files are inaccessible")
|
||||||
|
|
||||||
|
ap = app.add_argument_group("compatibility")
|
||||||
ap.add_argument("--cls", action="store_true", help="clear screen before start")
|
ap.add_argument("--cls", action="store_true", help="clear screen before start")
|
||||||
|
ap.add_argument("--ws", action="store_true", help="copyparty is running on windows; wait before deleting files after uploading")
|
||||||
|
|
||||||
ap = app.add_argument_group("folder sync")
|
ap = app.add_argument_group("folder sync")
|
||||||
ap.add_argument("--dl", action="store_true", help="delete local files after uploading")
|
ap.add_argument("--dl", action="store_true", help="delete local files after uploading")
|
||||||
@ -1031,10 +1034,14 @@ source file/folder selection uses rsync syntax, meaning that:
|
|||||||
if ar.cls:
|
if ar.cls:
|
||||||
print("\x1b\x5b\x48\x1b\x5b\x32\x4a\x1b\x5b\x33\x4a", end="")
|
print("\x1b\x5b\x48\x1b\x5b\x32\x4a\x1b\x5b\x33\x4a", end="")
|
||||||
|
|
||||||
Ctl(ar)
|
ctl = Ctl(ar)
|
||||||
|
|
||||||
if ar.dr and not ar.drd:
|
if ar.dr and not ar.drd:
|
||||||
# run another pass for the deletes
|
# run another pass for the deletes
|
||||||
|
if getattr(ctl, "up_br") and ar.ws:
|
||||||
|
# wait for up2k to mtime if there was uploads
|
||||||
|
time.sleep(4)
|
||||||
|
|
||||||
ar.drd = True
|
ar.drd = True
|
||||||
ar.z = True
|
ar.z = True
|
||||||
Ctl(ar)
|
Ctl(ar)
|
||||||
|
@ -1569,7 +1569,7 @@ class HttpCli(object):
|
|||||||
body["vcfg"] = dbv.flags
|
body["vcfg"] = dbv.flags
|
||||||
|
|
||||||
if not self.can_delete:
|
if not self.can_delete:
|
||||||
body.pop("replace")
|
body.pop("replace", None)
|
||||||
|
|
||||||
if rem:
|
if rem:
|
||||||
dst = vfs.canonical(rem)
|
dst = vfs.canonical(rem)
|
||||||
|
@ -97,7 +97,7 @@ class U2idx(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
cur = None
|
cur = None
|
||||||
if ANYWIN and bos.path.exists(db_path + "-wal"):
|
if ANYWIN and not bos.path.exists(db_path + "-wal"):
|
||||||
uri = ""
|
uri = ""
|
||||||
try:
|
try:
|
||||||
uri = "{}?mode=ro&nolock=1".format(Path(db_path).as_uri())
|
uri = "{}?mode=ro&nolock=1".format(Path(db_path).as_uri())
|
||||||
|
@ -153,6 +153,7 @@ class Up2k(object):
|
|||||||
if ANYWIN:
|
if ANYWIN:
|
||||||
# usually fails to set lastmod too quickly
|
# usually fails to set lastmod too quickly
|
||||||
self.lastmod_q: list[tuple[str, int, tuple[int, int], bool]] = []
|
self.lastmod_q: list[tuple[str, int, tuple[int, int], bool]] = []
|
||||||
|
self.lastmod_q2 = self.lastmod_q[:]
|
||||||
Daemon(self._lastmodder, "up2k-lastmod")
|
Daemon(self._lastmodder, "up2k-lastmod")
|
||||||
|
|
||||||
self.fstab = Fstab(self.log_func)
|
self.fstab = Fstab(self.log_func)
|
||||||
@ -3070,11 +3071,11 @@ class Up2k(object):
|
|||||||
|
|
||||||
def _lastmodder(self) -> None:
|
def _lastmodder(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
ready = self.lastmod_q
|
ready = self.lastmod_q2
|
||||||
|
self.lastmod_q2 = self.lastmod_q
|
||||||
self.lastmod_q = []
|
self.lastmod_q = []
|
||||||
|
|
||||||
# self.log("lmod: got {}".format(len(ready)))
|
time.sleep(1)
|
||||||
time.sleep(5)
|
|
||||||
for path, sz, times, sparse in ready:
|
for path, sz, times, sparse in ready:
|
||||||
self.log("lmod: setting times {} on {}".format(times, path))
|
self.log("lmod: setting times {} on {}".format(times, path))
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user