mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
indicate sqlite thread-safety + some cleanup
This commit is contained in:
parent
eeed2a840c
commit
51c152ff4a
|
@ -118,12 +118,13 @@ class BasicDodge11874(
|
|||
|
||||
|
||||
def lprint(*a: Any, **ka: Any) -> None:
|
||||
txt: str = " ".join(unicode(x) for x in a) + ka.get("end", "\n")
|
||||
eol = ka.pop("end", "\n")
|
||||
txt: str = " ".join(unicode(x) for x in a) + eol
|
||||
printed.append(txt)
|
||||
if not VT100:
|
||||
txt = ansi_re.sub("", txt)
|
||||
|
||||
print(txt, **ka)
|
||||
print(txt, end="", **ka)
|
||||
|
||||
|
||||
def warn(msg: str) -> None:
|
||||
|
@ -138,7 +139,7 @@ def ensure_locale() -> None:
|
|||
]:
|
||||
try:
|
||||
locale.setlocale(locale.LC_ALL, x)
|
||||
lprint("Locale:", x)
|
||||
lprint("Locale: {}\n".format(x))
|
||||
break
|
||||
except:
|
||||
continue
|
||||
|
|
|
@ -17,6 +17,7 @@ from .bos import bos
|
|||
from .util import (
|
||||
IMPLICATIONS,
|
||||
META_NOBOTS,
|
||||
SQLITE_VER,
|
||||
Pebkac,
|
||||
absreal,
|
||||
fsenc,
|
||||
|
@ -1165,7 +1166,7 @@ class AuthSrv(object):
|
|||
|
||||
vfs.bubble_flags()
|
||||
|
||||
e2vs = []
|
||||
have_e2d = False
|
||||
t = "volumes and permissions:\n"
|
||||
for zv in vfs.all_vols.values():
|
||||
if not self.warn_anonwrite:
|
||||
|
@ -1184,24 +1185,27 @@ class AuthSrv(object):
|
|||
u = u if u else "\033[36m--none--\033[0m"
|
||||
t += "\n| {}: {}".format(txt, u)
|
||||
|
||||
if "e2v" in zv.flags:
|
||||
e2vs.append(zv.vpath or "/")
|
||||
if "e2d" in zv.flags:
|
||||
have_e2d = True
|
||||
|
||||
t += "\n"
|
||||
|
||||
if e2vs:
|
||||
t += "\n\033[33me2v enabled for the following volumes;\nuploads will be blocked until scan has finished:\n \033[0m"
|
||||
t += " ".join(e2vs) + "\n"
|
||||
if self.warn_anonwrite:
|
||||
if not self.args.no_voldump:
|
||||
self.log(t)
|
||||
|
||||
if self.warn_anonwrite and not self.args.no_voldump:
|
||||
self.log(t)
|
||||
if have_e2d:
|
||||
t = self.chk_sqlite_threadsafe()
|
||||
if t:
|
||||
self.log("\n\033[{}\033[0m\n".format(t))
|
||||
|
||||
try:
|
||||
zv, _ = vfs.get("/", "*", False, True)
|
||||
if self.warn_anonwrite and os.getcwd() == zv.realpath:
|
||||
self.warn_anonwrite = False
|
||||
t = "anyone can write to the current directory: {}\n"
|
||||
self.log(t.format(zv.realpath), c=1)
|
||||
|
||||
self.warn_anonwrite = False
|
||||
except Pebkac:
|
||||
self.warn_anonwrite = True
|
||||
|
||||
|
@ -1215,6 +1219,23 @@ class AuthSrv(object):
|
|||
if pwds:
|
||||
self.re_pwd = re.compile("=(" + "|".join(pwds) + ")([]&; ]|$)")
|
||||
|
||||
def chk_sqlite_threadsafe(self) -> str:
|
||||
v = SQLITE_VER[-1:]
|
||||
|
||||
if v == "1":
|
||||
# threadsafe (linux, windows)
|
||||
return ""
|
||||
|
||||
if v == "2":
|
||||
# module safe, connections unsafe (macos)
|
||||
return "33m your sqlite3 was compiled with reduced thread-safety;\n database features (-e2d, -e2t) SHOULD be fine\n but MAY cause database-corruption and crashes"
|
||||
|
||||
if v == "0":
|
||||
# everything unsafe
|
||||
return "31m your sqlite3 was compiled WITHOUT thread-safety!\n database features (-e2d, -e2t) will PROBABLY cause crashes!"
|
||||
|
||||
return "36m cannot verify sqlite3 thread-safety; strange but probably fine"
|
||||
|
||||
def dbg_ls(self) -> None:
|
||||
users = self.args.ls
|
||||
vol = "*"
|
||||
|
|
|
@ -146,8 +146,8 @@ class SvcHub(object):
|
|||
self.args.th_dec = list(decs.keys())
|
||||
self.thumbsrv = None
|
||||
if not args.no_thumb:
|
||||
t = "decoder preference: {}".format(", ".join(self.args.th_dec))
|
||||
self.log("thumb", t)
|
||||
t = ", ".join(self.args.th_dec) or "(None available)"
|
||||
self.log("thumb", "decoder preference: {}".format(t))
|
||||
|
||||
if "pil" in self.args.th_dec and not HAVE_WEBP:
|
||||
msg = "disabling webp thumbnails because either libwebp is not available or your Pillow is too old"
|
||||
|
|
|
@ -235,8 +235,26 @@ def py_desc() -> str:
|
|||
)
|
||||
|
||||
|
||||
def _sqlite_ver() -> str:
|
||||
try:
|
||||
co = sqlite3.connect(":memory:")
|
||||
cur = co.cursor()
|
||||
try:
|
||||
vs = cur.execute("select * from pragma_compile_options").fetchall()
|
||||
except:
|
||||
vs = cur.execute("pragma compile_options").fetchall()
|
||||
|
||||
v = next(x[0].split("=")[1] for x in vs if x[0].startswith("THREADSAFE="))
|
||||
cur.close()
|
||||
co.close()
|
||||
except:
|
||||
v = "W"
|
||||
|
||||
return "{}*{}".format(sqlite3.sqlite_version, v)
|
||||
|
||||
|
||||
try:
|
||||
from sqlite3 import sqlite_version as SQLITE_VER
|
||||
SQLITE_VER = _sqlite_ver()
|
||||
except:
|
||||
SQLITE_VER = "(None)"
|
||||
|
||||
|
|
Loading…
Reference in a new issue