try to avoid printing mojibake in logs

unprintable and side-effect-inducing paths and names are hex-escaped,
preserving greppability and making log-parsing slightly more okay
This commit is contained in:
ed 2024-12-18 01:45:54 +01:00
parent 4c4e48bab7
commit 3051b13108
12 changed files with 185 additions and 186 deletions

View file

@ -212,7 +212,7 @@ class Lim(object):
df, du, err = get_df(abspath, True) df, du, err = get_df(abspath, True)
if err: if err:
t = "failed to read disk space usage for [%s]: %s" t = "failed to read disk space usage for %r: %s"
self.log(t % (abspath, err), 3) self.log(t % (abspath, err), 3)
self.dfv = 0xAAAAAAAAA # 42.6 GiB self.dfv = 0xAAAAAAAAA # 42.6 GiB
else: else:
@ -526,7 +526,7 @@ class VFS(object):
"""returns [vfsnode,fs_remainder] if user has the requested permissions""" """returns [vfsnode,fs_remainder] if user has the requested permissions"""
if relchk(vpath): if relchk(vpath):
if self.log: if self.log:
self.log("vfs", "invalid relpath [{}]".format(vpath)) self.log("vfs", "invalid relpath %r @%s" % (vpath, uname))
raise Pebkac(422) raise Pebkac(422)
cvpath = undot(vpath) cvpath = undot(vpath)
@ -543,11 +543,11 @@ class VFS(object):
if req and uname not in d and uname != LEELOO_DALLAS: if req and uname not in d and uname != LEELOO_DALLAS:
if vpath != cvpath and vpath != "." and self.log: if vpath != cvpath and vpath != "." and self.log:
ap = vn.canonical(rem) ap = vn.canonical(rem)
t = "{} has no {} in [{}] => [{}] => [{}]" t = "%s has no %s in %r => %r => %r"
self.log("vfs", t.format(uname, msg, vpath, cvpath, ap), 6) self.log("vfs", t % (uname, msg, vpath, cvpath, ap), 6)
t = 'you don\'t have %s-access in "/%s" or below "/%s"' t = "you don't have %s-access in %r or below %r"
raise Pebkac(err, t % (msg, cvpath, vn.vpath)) raise Pebkac(err, t % (msg, "/" + cvpath, "/" + vn.vpath))
return vn, rem return vn, rem
@ -693,8 +693,8 @@ class VFS(object):
and fsroot in seen and fsroot in seen
): ):
if self.log: if self.log:
t = "bailing from symlink loop,\n prev: {}\n curr: {}\n from: {}/{}" t = "bailing from symlink loop,\n prev: %r\n curr: %r\n from: %r / %r"
self.log("vfs.walk", t.format(seen[-1], fsroot, self.vpath, rem), 3) self.log("vfs.walk", t % (seen[-1], fsroot, self.vpath, rem), 3)
return return
if "xdev" in self.flags or "xvol" in self.flags: if "xdev" in self.flags or "xvol" in self.flags:
@ -818,8 +818,8 @@ class VFS(object):
if vdev != st.st_dev: if vdev != st.st_dev:
if self.log: if self.log:
t = "xdev: {}[{}] => {}[{}]" t = "xdev: %s[%r] => %s[%r]"
self.log("vfs", t.format(vdev, self.realpath, st.st_dev, ap), 3) self.log("vfs", t % (vdev, self.realpath, st.st_dev, ap), 3)
return None return None
@ -829,7 +829,7 @@ class VFS(object):
return vn return vn
if self.log: if self.log:
self.log("vfs", "xvol: [{}]".format(ap), 3) self.log("vfs", "xvol: %r" % (ap,), 3)
return None return None
@ -914,7 +914,7 @@ class AuthSrv(object):
self.idp_accs[uname] = gnames self.idp_accs[uname] = gnames
t = "reinitializing due to new user from IdP: [%s:%s]" t = "reinitializing due to new user from IdP: [%r:%r]"
self.log(t % (uname, gnames), 3) self.log(t % (uname, gnames), 3)
if not broker: if not broker:
@ -1568,7 +1568,7 @@ class AuthSrv(object):
continue continue
if self.args.shr_v: if self.args.shr_v:
t = "loading %s share [%s] by [%s] => [%s]" t = "loading %s share %r by %r => %r"
self.log(t % (s_pr, s_k, s_un, s_vp)) self.log(t % (s_pr, s_k, s_un, s_vp))
if s_pw: if s_pw:
@ -1765,7 +1765,7 @@ class AuthSrv(object):
use = True use = True
try: try:
_ = float(zs) _ = float(zs)
zs = "%sg" % (zs) zs = "%sg" % (zs,)
except: except:
pass pass
lim.dfl = unhumanize(zs) lim.dfl = unhumanize(zs)
@ -2538,7 +2538,7 @@ class AuthSrv(object):
return return
elif self.args.chpw_v == 2: elif self.args.chpw_v == 2:
t = "chpw: %d changed" % (len(uok)) t = "chpw: %d changed" % (len(uok),)
if urst: if urst:
t += ", \033[0munchanged:\033[35m %s" % (", ".join(list(urst))) t += ", \033[0munchanged:\033[35m %s" % (", ".join(list(urst)))

View file

@ -42,14 +42,14 @@ class Fstab(object):
self.cache = {} self.cache = {}
fs = "ext4" fs = "ext4"
msg = "failed to determine filesystem at [{}]; assuming {}\n{}" msg = "failed to determine filesystem at %r; assuming %s\n%s"
if ANYWIN: if ANYWIN:
fs = "vfat" fs = "vfat"
try: try:
path = self._winpath(path) path = self._winpath(path)
except: except:
self.log(msg.format(path, fs, min_ex()), 3) self.log(msg % (path, fs, min_ex()), 3)
return fs return fs
path = undot(path) path = undot(path)
@ -61,11 +61,11 @@ class Fstab(object):
try: try:
fs = self.get_w32(path) if ANYWIN else self.get_unix(path) fs = self.get_w32(path) if ANYWIN else self.get_unix(path)
except: except:
self.log(msg.format(path, fs, min_ex()), 3) self.log(msg % (path, fs, min_ex()), 3)
fs = fs.lower() fs = fs.lower()
self.cache[path] = fs self.cache[path] = fs
self.log("found {} at {}".format(fs, path)) self.log("found %s at %r" % (fs, path))
return fs return fs
def _winpath(self, path: str) -> str: def _winpath(self, path: str) -> str:

View file

@ -479,8 +479,8 @@ class HttpCli(object):
if vpath.startswith(self.args.R): if vpath.startswith(self.args.R):
vpath = vpath[len(self.args.R) + 1 :] vpath = vpath[len(self.args.R) + 1 :]
else: else:
t = "incorrect --rp-loc or webserver config; expected vpath starting with [{}] but got [{}]" t = "incorrect --rp-loc or webserver config; expected vpath starting with %r but got %r"
self.log(t.format(self.args.R, vpath), 1) self.log(t % (self.args.R, vpath), 1)
self.ouparam = uparam.copy() self.ouparam = uparam.copy()
@ -518,7 +518,7 @@ class HttpCli(object):
return self.tx_qr() return self.tx_qr()
if relchk(self.vpath) and (self.vpath != "*" or self.mode != "OPTIONS"): if relchk(self.vpath) and (self.vpath != "*" or self.mode != "OPTIONS"):
self.log("invalid relpath [{}]".format(self.vpath)) self.log("invalid relpath %r" % ("/" + self.vpath,))
self.cbonk(self.conn.hsrv.gmal, self.req, "bad_vp", "invalid relpaths") self.cbonk(self.conn.hsrv.gmal, self.req, "bad_vp", "invalid relpaths")
return self.tx_404() and self.keepalive return self.tx_404() and self.keepalive
@ -598,7 +598,7 @@ class HttpCli(object):
self.uname = idp_usr self.uname = idp_usr
self.html_head += "<script>var is_idp=1</script>\n" self.html_head += "<script>var is_idp=1</script>\n"
else: else:
self.log("unknown username: [%s]" % (idp_usr), 1) self.log("unknown username: %r" % (idp_usr,), 1)
if self.args.ipu and self.uname == "*": if self.args.ipu and self.uname == "*":
self.uname = self.conn.ipu_iu[self.conn.ipu_nm.map(self.ip)] self.uname = self.conn.ipu_iu[self.conn.ipu_nm.map(self.ip)]
@ -663,7 +663,7 @@ class HttpCli(object):
origin = self.headers.get("origin", "<?>") origin = self.headers.get("origin", "<?>")
proto = "https://" if self.is_https else "http://" proto = "https://" if self.is_https else "http://"
guess = "modifying" if (origin and host) else "stripping" guess = "modifying" if (origin and host) else "stripping"
t = "cors-reject %s because request-header Origin='%s' does not match request-protocol '%s' and host '%s' based on request-header Host='%s' (note: if this request is not malicious, check if your reverse-proxy is accidentally %s request headers, in particular 'Origin', for example by running copyparty with --ihead='*' to show all request headers)" t = "cors-reject %s because request-header Origin=%r does not match request-protocol %r and host %r based on request-header Host=%r (note: if this request is not malicious, check if your reverse-proxy is accidentally %s request headers, in particular 'Origin', for example by running copyparty with --ihead='*' to show all request headers)"
self.log(t % (self.mode, origin, proto, self.host, host, guess), 3) self.log(t % (self.mode, origin, proto, self.host, host, guess), 3)
raise Pebkac(403, "rejected by cors-check") raise Pebkac(403, "rejected by cors-check")
@ -709,7 +709,7 @@ class HttpCli(object):
if pex.code != 404 or self.do_log: if pex.code != 404 or self.do_log:
self.log( self.log(
"http%d: %s\033[0m, %s" % (pex.code, msg, self.vpath), "http%d: %s\033[0m, %r" % (pex.code, msg, "/" + self.vpath),
6 if em.startswith("client d/c ") else 3, 6 if em.startswith("client d/c ") else 3,
) )
@ -1154,8 +1154,8 @@ class HttpCli(object):
return self.tx_res(res_path) return self.tx_res(res_path)
if res_path != undot(res_path): if res_path != undot(res_path):
t = "malicious user; attempted path traversal [{}] => [{}]" t = "malicious user; attempted path traversal %r => %r"
self.log(t.format(self.vpath, res_path), 1) self.log(t % ("/" + self.vpath, res_path), 1)
self.cbonk(self.conn.hsrv.gmal, self.req, "trav", "path traversal") self.cbonk(self.conn.hsrv.gmal, self.req, "trav", "path traversal")
self.tx_404() self.tx_404()
@ -1166,11 +1166,11 @@ class HttpCli(object):
return True return True
if not self.can_read and not self.can_write and not self.can_get: if not self.can_read and not self.can_write and not self.can_get:
t = "@{} has no access to [{}]" t = "@%s has no access to %r"
if "on403" in self.vn.flags: if "on403" in self.vn.flags:
t += " (on403)" t += " (on403)"
self.log(t.format(self.uname, self.vpath)) self.log(t % (self.uname, "/" + self.vpath))
ret = self.on40x(self.vn.flags["on403"], self.vn, self.rem) ret = self.on40x(self.vn.flags["on403"], self.vn, self.rem)
if ret == "true": if ret == "true":
return True return True
@ -1189,7 +1189,7 @@ class HttpCli(object):
if self.vpath: if self.vpath:
ptn = self.args.nonsus_urls ptn = self.args.nonsus_urls
if not ptn or not ptn.search(self.vpath): if not ptn or not ptn.search(self.vpath):
self.log(t.format(self.uname, self.vpath)) self.log(t % (self.uname, "/" + self.vpath))
return self.tx_404(True) return self.tx_404(True)
@ -1435,14 +1435,14 @@ class HttpCli(object):
if depth == "infinity": if depth == "infinity":
# allow depth:0 from unmapped root, but require read-axs otherwise # allow depth:0 from unmapped root, but require read-axs otherwise
if not self.can_read and (self.vpath or self.asrv.vfs.realpath): if not self.can_read and (self.vpath or self.asrv.vfs.realpath):
t = "depth:infinity requires read-access in /%s" t = "depth:infinity requires read-access in %r"
t = t % (self.vpath,) t = t % ("/" + self.vpath,)
self.log(t, 3) self.log(t, 3)
raise Pebkac(401, t) raise Pebkac(401, t)
if not stat.S_ISDIR(topdir["st"].st_mode): if not stat.S_ISDIR(topdir["st"].st_mode):
t = "depth:infinity can only be used on folders; /%s is 0o%o" t = "depth:infinity can only be used on folders; %r is 0o%o"
t = t % (self.vpath, topdir["st"]) t = t % ("/" + self.vpath, topdir["st"])
self.log(t, 3) self.log(t, 3)
raise Pebkac(400, t) raise Pebkac(400, t)
@ -1468,7 +1468,7 @@ class HttpCli(object):
elif depth == "0" or not stat.S_ISDIR(st.st_mode): elif depth == "0" or not stat.S_ISDIR(st.st_mode):
# propfind on a file; return as topdir # propfind on a file; return as topdir
if not self.can_read and not self.can_get: if not self.can_read and not self.can_get:
self.log("inaccessible: [%s]" % (self.vpath,)) self.log("inaccessible: %r" % ("/" + self.vpath,))
raise Pebkac(401, "authenticate") raise Pebkac(401, "authenticate")
elif depth == "1": elif depth == "1":
@ -1495,7 +1495,7 @@ class HttpCli(object):
raise Pebkac(412, t.format(depth, t2)) raise Pebkac(412, t.format(depth, t2))
if not self.can_read and not self.can_write and not fgen: if not self.can_read and not self.can_write and not fgen:
self.log("inaccessible: [%s]" % (self.vpath,)) self.log("inaccessible: %r" % ("/" + self.vpath,))
raise Pebkac(401, "authenticate") raise Pebkac(401, "authenticate")
fgen = itertools.chain([topdir], fgen) fgen = itertools.chain([topdir], fgen)
@ -1573,7 +1573,7 @@ class HttpCli(object):
raise Pebkac(405, "WebDAV is disabled in server config") raise Pebkac(405, "WebDAV is disabled in server config")
if not self.can_write: if not self.can_write:
self.log("{} tried to proppatch [{}]".format(self.uname, self.vpath)) self.log("%s tried to proppatch %r" % (self.uname, "/" + self.vpath))
raise Pebkac(401, "authenticate") raise Pebkac(401, "authenticate")
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
@ -1631,7 +1631,7 @@ class HttpCli(object):
# win7+ deadlocks if we say no; just smile and nod # win7+ deadlocks if we say no; just smile and nod
if not self.can_write and "Microsoft-WebDAV" not in self.ua: if not self.can_write and "Microsoft-WebDAV" not in self.ua:
self.log("{} tried to lock [{}]".format(self.uname, self.vpath)) self.log("%s tried to lock %r" % (self.uname, "/" + self.vpath))
raise Pebkac(401, "authenticate") raise Pebkac(401, "authenticate")
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
@ -1697,7 +1697,7 @@ class HttpCli(object):
raise Pebkac(405, "WebDAV is disabled in server config") raise Pebkac(405, "WebDAV is disabled in server config")
if not self.can_write and "Microsoft-WebDAV" not in self.ua: if not self.can_write and "Microsoft-WebDAV" not in self.ua:
self.log("{} tried to lock [{}]".format(self.uname, self.vpath)) self.log("%s tried to lock %r" % (self.uname, "/" + self.vpath))
raise Pebkac(401, "authenticate") raise Pebkac(401, "authenticate")
self.send_headers(None, 204) self.send_headers(None, 204)
@ -1851,7 +1851,7 @@ class HttpCli(object):
if "save" in opt: if "save" in opt:
post_sz, _, _, _, path, _ = self.dump_to_file(False) post_sz, _, _, _, path, _ = self.dump_to_file(False)
self.log("urlform: {} bytes, {}".format(post_sz, path)) self.log("urlform: %d bytes, %r" % (post_sz, path))
elif "print" in opt: elif "print" in opt:
reader, _ = self.get_body_reader() reader, _ = self.get_body_reader()
buf = b"" buf = b""
@ -1862,8 +1862,8 @@ class HttpCli(object):
if buf: if buf:
orig = buf.decode("utf-8", "replace") orig = buf.decode("utf-8", "replace")
t = "urlform_raw {} @ {}\n {}\n" t = "urlform_raw %d @ %r\n %r\n"
self.log(t.format(len(orig), self.vpath, orig)) self.log(t % (len(orig), "/" + self.vpath, orig))
try: try:
zb = unquote(buf.replace(b"+", b" ")) zb = unquote(buf.replace(b"+", b" "))
plain = zb.decode("utf-8", "replace") plain = zb.decode("utf-8", "replace")
@ -1889,8 +1889,8 @@ class HttpCli(object):
plain, plain,
) )
t = "urlform_dec {} @ {}\n {}\n" t = "urlform_dec %d @ %r\n %r\n"
self.log(t.format(len(plain), self.vpath, plain)) self.log(t % (len(plain), "/" + self.vpath, plain))
except Exception as ex: except Exception as ex:
self.log(repr(ex)) self.log(repr(ex))
@ -2140,7 +2140,7 @@ class HttpCli(object):
try: try:
ext = self.conn.hsrv.magician.ext(path) ext = self.conn.hsrv.magician.ext(path)
except Exception as ex: except Exception as ex:
self.log("filetype detection failed for [{}]: {}".format(path, ex), 6) self.log("filetype detection failed for %r: %s" % (path, ex), 6)
ext = None ext = None
if ext: if ext:
@ -2240,8 +2240,8 @@ class HttpCli(object):
def handle_stash(self, is_put: bool) -> bool: def handle_stash(self, is_put: bool) -> bool:
post_sz, sha_hex, sha_b64, remains, path, url = self.dump_to_file(is_put) post_sz, sha_hex, sha_b64, remains, path, url = self.dump_to_file(is_put)
spd = self._spd(post_sz) spd = self._spd(post_sz)
t = "{} wrote {}/{} bytes to {} # {}" t = "%s wrote %d/%d bytes to %r # %s"
self.log(t.format(spd, post_sz, remains, path, sha_b64[:28])) # 21 self.log(t % (spd, post_sz, remains, path, sha_b64[:28])) # 21
ac = self.uparam.get( ac = self.uparam.get(
"want", self.headers.get("accept", "").lower().split(";")[-1] "want", self.headers.get("accept", "").lower().split(";")[-1]
@ -2271,7 +2271,7 @@ class HttpCli(object):
flags: dict[str, Any], flags: dict[str, Any],
) -> None: ) -> None:
now = time.time() now = time.time()
t = "bad-chunk: %.3f %s %s %d %s %s %s" t = "bad-chunk: %.3f %s %s %d %s %s %r"
t = t % (now, bad_sha, good_sha, ofs, self.ip, self.uname, ap) t = t % (now, bad_sha, good_sha, ofs, self.ip, self.uname, ap)
self.log(t, 5) self.log(t, 5)
@ -2411,7 +2411,7 @@ class HttpCli(object):
body = json.loads(json_buf.decode(enc, "replace")) body = json.loads(json_buf.decode(enc, "replace"))
try: try:
zds = {k: v for k, v in body.items()} zds = {k: v for k, v in body.items()}
zds["hash"] = "%d chunks" % (len(body["hash"])) zds["hash"] = "%d chunks" % (len(body["hash"]),)
except: except:
zds = body zds = body
t = "POST len=%d type=%s ip=%s user=%s req=%r json=%s" t = "POST len=%d type=%s ip=%s user=%s req=%r json=%s"
@ -2455,7 +2455,7 @@ class HttpCli(object):
if not bos.path.isdir(dst): if not bos.path.isdir(dst):
bos.makedirs(dst) bos.makedirs(dst)
except OSError as ex: except OSError as ex:
self.log("makedirs failed [{}]".format(dst)) self.log("makedirs failed %r" % (dst,))
if not bos.path.isdir(dst): if not bos.path.isdir(dst):
if ex.errno == errno.EACCES: if ex.errno == errno.EACCES:
raise Pebkac(500, "the server OS denied write-access") raise Pebkac(500, "the server OS denied write-access")
@ -2480,7 +2480,7 @@ class HttpCli(object):
# strip common suffix (uploader's folder structure) # strip common suffix (uploader's folder structure)
vp_req, vp_vfs = vroots(self.vpath, vjoin(dbv.vpath, vrem)) vp_req, vp_vfs = vroots(self.vpath, vjoin(dbv.vpath, vrem))
if not ret["purl"].startswith(vp_vfs): if not ret["purl"].startswith(vp_vfs):
t = "share-mapping failed; req=[%s] dbv=[%s] vrem=[%s] n1=[%s] n2=[%s] purl=[%s]" t = "share-mapping failed; req=%r dbv=%r vrem=%r n1=%r n2=%r purl=%r"
zt = (self.vpath, dbv.vpath, vrem, vp_req, vp_vfs, ret["purl"]) zt = (self.vpath, dbv.vpath, vrem, vp_req, vp_vfs, ret["purl"])
raise Pebkac(500, t % zt) raise Pebkac(500, t % zt)
ret["purl"] = vp_req + ret["purl"][len(vp_vfs) :] ret["purl"] = vp_req + ret["purl"][len(vp_vfs) :]
@ -2529,13 +2529,13 @@ class HttpCli(object):
# search by query params # search by query params
q = body["q"] q = body["q"]
n = body.get("n", self.args.srch_hits) n = body.get("n", self.args.srch_hits)
self.log("qj: {} |{}|".format(q, n)) self.log("qj: %r |%d|" % (q, n))
hits, taglist, trunc = idx.search(self.uname, vols, q, n) hits, taglist, trunc = idx.search(self.uname, vols, q, n)
msg = len(hits) msg = len(hits)
idx.p_end = time.time() idx.p_end = time.time()
idx.p_dur = idx.p_end - t0 idx.p_dur = idx.p_end - t0
self.log("q#: {} ({:.2f}s)".format(msg, idx.p_dur)) self.log("q#: %r (%.2fs)" % (msg, idx.p_dur))
order = [] order = []
for t in self.args.mte: for t in self.args.mte:
@ -2646,7 +2646,7 @@ class HttpCli(object):
t = "your client is sending %d bytes which is too much (server expected %d bytes at most)" t = "your client is sending %d bytes which is too much (server expected %d bytes at most)"
raise Pebkac(400, t % (remains, maxsize)) raise Pebkac(400, t % (remains, maxsize))
t = "writing %s %s+%d #%d+%d %s" t = "writing %r %s+%d #%d+%d %s"
chunkno = cstart0[0] // chunksize chunkno = cstart0[0] // chunksize
zs = " ".join([chashes[0][:15]] + [x[:9] for x in chashes[1:]]) zs = " ".join([chashes[0][:15]] + [x[:9] for x in chashes[1:]])
self.log(t % (path, cstart0, remains, chunkno, len(chashes), zs)) self.log(t % (path, cstart0, remains, chunkno, len(chashes), zs))
@ -2758,7 +2758,7 @@ class HttpCli(object):
cinf = self.headers.get("x-up2k-stat", "") cinf = self.headers.get("x-up2k-stat", "")
spd = self._spd(postsize) spd = self._spd(postsize)
self.log("{:70} thank {}".format(spd, cinf)) self.log("%70s thank %r" % (spd, cinf))
self.reply(b"thank") self.reply(b"thank")
return True return True
@ -2840,7 +2840,7 @@ class HttpCli(object):
logpwd = "%" + ub64enc(zb[:12]).decode("ascii") logpwd = "%" + ub64enc(zb[:12]).decode("ascii")
if pwd != "x": if pwd != "x":
self.log("invalid password: {}".format(logpwd), 3) self.log("invalid password: %r" % (logpwd,), 3)
self.cbonk(self.conn.hsrv.gpwd, pwd, "pw", "invalid passwords") self.cbonk(self.conn.hsrv.gpwd, pwd, "pw", "invalid passwords")
msg = "naw dude" msg = "naw dude"
@ -2876,7 +2876,7 @@ class HttpCli(object):
rem = sanitize_vpath(rem, "/") rem = sanitize_vpath(rem, "/")
fn = vfs.canonical(rem) fn = vfs.canonical(rem)
if not fn.startswith(vfs.realpath): if not fn.startswith(vfs.realpath):
self.log("invalid mkdir [%s] [%s]" % (self.gctx, vpath), 1) self.log("invalid mkdir %r %r" % (self.gctx, vpath), 1)
raise Pebkac(422) raise Pebkac(422)
if not nullwrite: if not nullwrite:
@ -3042,9 +3042,9 @@ class HttpCli(object):
elif bos.path.exists(abspath): elif bos.path.exists(abspath):
try: try:
wunlink(self.log, abspath, vfs.flags) wunlink(self.log, abspath, vfs.flags)
t = "overwriting file with new upload: %s" t = "overwriting file with new upload: %r"
except: except:
t = "toctou while deleting for ?replace: %s" t = "toctou while deleting for ?replace: %r"
self.log(t % (abspath,)) self.log(t % (abspath,))
else: else:
open_args = {} open_args = {}
@ -3127,7 +3127,7 @@ class HttpCli(object):
f, tnam = ren_open(tnam, "wb", self.args.iobuf, **open_args) f, tnam = ren_open(tnam, "wb", self.args.iobuf, **open_args)
try: try:
tabspath = os.path.join(fdir, tnam) tabspath = os.path.join(fdir, tnam)
self.log("writing to {}".format(tabspath)) self.log("writing to %r" % (tabspath,))
sz, sha_hex, sha_b64 = copier( sz, sha_hex, sha_b64 = copier(
p_data, f, hasher, max_sz, self.args.s_wr_slp p_data, f, hasher, max_sz, self.args.s_wr_slp
) )
@ -3312,7 +3312,7 @@ class HttpCli(object):
jmsg["files"].append(jpart) jmsg["files"].append(jpart)
vspd = self._spd(sz_total, False) vspd = self._spd(sz_total, False)
self.log("{} {}".format(vspd, msg)) self.log("%s %r" % (vspd, msg))
suf = "" suf = ""
if not nullwrite and self.args.write_uplog: if not nullwrite and self.args.write_uplog:
@ -3575,7 +3575,7 @@ class HttpCli(object):
if req == zs: if req == zs:
return True return True
t = "wrong dirkey, want %s, got %s\n vp: %s\n ap: %s" t = "wrong dirkey, want %s, got %s\n vp: %r\n ap: %r"
self.log(t % (zs, req, self.req, ap), 6) self.log(t % (zs, req, self.req, ap), 6)
return False return False
@ -3603,7 +3603,7 @@ class HttpCli(object):
if req == zs: if req == zs:
return True return True
t = "wrong filekey, want %s, got %s\n vp: %s\n ap: %s" t = "wrong filekey, want %s, got %s\n vp: %r\n ap: %r"
self.log(t % (zs, req, self.req, ap), 6) self.log(t % (zs, req, self.req, ap), 6)
return False return False
@ -3665,7 +3665,7 @@ class HttpCli(object):
elif ph == "srv.htime": elif ph == "srv.htime":
sv = datetime.now(UTC).strftime("%Y-%m-%d, %H:%M:%S") sv = datetime.now(UTC).strftime("%Y-%m-%d, %H:%M:%S")
else: else:
self.log("unknown placeholder in server config: [%s]" % (ph), 3) self.log("unknown placeholder in server config: [%s]" % (ph,), 3)
continue continue
sv = self.conn.hsrv.ptn_hsafe.sub("_", sv) sv = self.conn.hsrv.ptn_hsafe.sub("_", sv)
@ -3822,7 +3822,7 @@ class HttpCli(object):
self.pipes.set(req_path, job) self.pipes.set(req_path, job)
except Exception as ex: except Exception as ex:
if getattr(ex, "errno", 0) != errno.ENOENT: if getattr(ex, "errno", 0) != errno.ENOENT:
self.log("will not pipe [%s]; %s" % (ap_data, ex), 6) self.log("will not pipe %r; %s" % (ap_data, ex), 6)
ptop = None ptop = None
# #
@ -4112,7 +4112,7 @@ class HttpCli(object):
if lower >= data_end: if lower >= data_end:
if data_end: if data_end:
t = "pipe: uploader is too slow; aborting download at %.2f MiB" t = "pipe: uploader is too slow; aborting download at %.2f MiB"
self.log(t % (data_end / M)) self.log(t % (data_end / M,))
raise Pebkac(416, "uploader is too slow") raise Pebkac(416, "uploader is too slow")
raise Pebkac(416, "no data available yet; please retry in a bit") raise Pebkac(416, "no data available yet; please retry in a bit")
@ -4256,7 +4256,7 @@ class HttpCli(object):
cdis = "attachment; filename=\"{}.{}\"; filename*=UTF-8''{}.{}" cdis = "attachment; filename=\"{}.{}\"; filename*=UTF-8''{}.{}"
cdis = cdis.format(afn, ext, ufn, ext) cdis = cdis.format(afn, ext, ufn, ext)
self.log(cdis) self.log(repr(cdis))
self.send_headers(None, mime=mime, headers={"Content-Disposition": cdis}) self.send_headers(None, mime=mime, headers={"Content-Disposition": cdis})
fgen = vn.zipgen( fgen = vn.zipgen(
@ -4920,7 +4920,7 @@ class HttpCli(object):
raise Pebkac(500, "server busy, cannot unpost; please retry in a bit") raise Pebkac(500, "server busy, cannot unpost; please retry in a bit")
filt = self.uparam.get("filter") or "" filt = self.uparam.get("filter") or ""
lm = "ups [{}]".format(filt) lm = "ups %r" % (filt,)
self.log(lm) self.log(lm)
if self.args.shr and self.vpath.startswith(self.args.shr1): if self.args.shr and self.vpath.startswith(self.args.shr1):
@ -5731,7 +5731,7 @@ class HttpCli(object):
linf = stats.get(fn) or bos.lstat(fspath) linf = stats.get(fn) or bos.lstat(fspath)
inf = bos.stat(fspath) if stat.S_ISLNK(linf.st_mode) else linf inf = bos.stat(fspath) if stat.S_ISLNK(linf.st_mode) else linf
except: except:
self.log("broken symlink: {}".format(repr(fspath))) self.log("broken symlink: %r" % (fspath,))
continue continue
is_dir = stat.S_ISDIR(inf.st_mode) is_dir = stat.S_ISDIR(inf.st_mode)
@ -5846,8 +5846,7 @@ class HttpCli(object):
erd_efn = s3enc(idx.mem_cur, rd, fn) erd_efn = s3enc(idx.mem_cur, rd, fn)
r = icur.execute(q, erd_efn) r = icur.execute(q, erd_efn)
except: except:
t = "tag read error, {}/{}\n{}" self.log("tag read error, %r / %r\n%s" % (rd, fn, min_ex()))
self.log(t.format(rd, fn, min_ex()))
break break
tags = {k: v for k, v in r} tags = {k: v for k, v in r}
@ -5967,10 +5966,10 @@ class HttpCli(object):
if doc.lower().endswith(".md") and "exp" in vn.flags: if doc.lower().endswith(".md") and "exp" in vn.flags:
doctxt = self._expand(doctxt, vn.flags.get("exp_md") or []) doctxt = self._expand(doctxt, vn.flags.get("exp_md") or [])
else: else:
self.log("doc 2big: [{}]".format(doc), c=6) self.log("doc 2big: %r" % (doc,), 6)
doctxt = "( size of textfile exceeds serverside limit )" doctxt = "( size of textfile exceeds serverside limit )"
else: else:
self.log("doc 404: [{}]".format(doc), c=6) self.log("doc 404: %r" % (doc,), 6)
doctxt = "( textfile not found )" doctxt = "( textfile not found )"
if doctxt is not None: if doctxt is not None:

View file

@ -194,7 +194,7 @@ def au_unpk(
except Exception as ex: except Exception as ex:
if ret: if ret:
t = "failed to decompress audio file [%s]: %r" t = "failed to decompress audio file %r: %r"
log(t % (abspath, ex)) log(t % (abspath, ex))
wunlink(log, ret, vn.flags if vn else VF_CAREFUL) wunlink(log, ret, vn.flags if vn else VF_CAREFUL)
@ -582,7 +582,7 @@ class MTag(object):
raise Exception() raise Exception()
except Exception as ex: except Exception as ex:
if self.args.mtag_v: if self.args.mtag_v:
self.log("mutagen-err [{}] @ [{}]".format(ex, abspath), "90") self.log("mutagen-err [%s] @ %r" % (ex, abspath), "90")
return self.get_ffprobe(abspath) if self.can_ffprobe else {} return self.get_ffprobe(abspath) if self.can_ffprobe else {}
@ -699,8 +699,8 @@ class MTag(object):
ret[tag] = zj[tag] ret[tag] = zj[tag]
except: except:
if self.args.mtag_v: if self.args.mtag_v:
t = "mtag error: tagname {}, parser {}, file {} => {}" t = "mtag error: tagname %r, parser %r, file %r => %r"
self.log(t.format(tagname, parser.bin, abspath, min_ex())) self.log(t % (tagname, parser.bin, abspath, min_ex()), 6)
if ap != abspath: if ap != abspath:
wunlink(self.log, ap, VF_CAREFUL) wunlink(self.log, ap, VF_CAREFUL)

View file

@ -263,7 +263,7 @@ class SMB(object):
time.time(), time.time(),
"", "",
): ):
yeet("blocked by xbu server config: " + vpath) yeet("blocked by xbu server config: %r" % (vpath,))
ret = bos.open(ap, flags, *a, mode=chmod, **ka) ret = bos.open(ap, flags, *a, mode=chmod, **ka)
if wr: if wr:

View file

@ -110,7 +110,7 @@ def errdesc(
report = ["copyparty failed to add the following files to the archive:", ""] report = ["copyparty failed to add the following files to the archive:", ""]
for fn, err in errors: for fn, err in errors:
report.extend([" file: {}".format(fn), "error: {}".format(err), ""]) report.extend([" file: %r" % (fn,), "error: %s" % (err,), ""])
btxt = "\r\n".join(report).encode("utf-8", "replace") btxt = "\r\n".join(report).encode("utf-8", "replace")
btxt = vol_san(list(vfs.all_vols.values()), btxt) btxt = vol_san(list(vfs.all_vols.values()), btxt)

View file

@ -357,7 +357,7 @@ class Tftpd(object):
time.time(), time.time(),
"", "",
): ):
yeet("blocked by xbu server config: " + vpath) yeet("blocked by xbu server config: %r" % (vpath,))
if not self.args.tftp_nols and bos.path.isdir(ap): if not self.args.tftp_nols and bos.path.isdir(ap):
return self._ls(vpath, "", 0, True) return self._ls(vpath, "", 0, True)

View file

@ -109,13 +109,13 @@ class ThumbCli(object):
fmt = sfmt fmt = sfmt
elif fmt[:1] == "p" and not is_au and not is_vid: elif fmt[:1] == "p" and not is_au and not is_vid:
t = "cannot thumbnail [%s]: png only allowed for waveforms" t = "cannot thumbnail %r: png only allowed for waveforms"
self.log(t % (rem), 6) self.log(t % (rem,), 6)
return None return None
histpath = self.asrv.vfs.histtab.get(ptop) histpath = self.asrv.vfs.histtab.get(ptop)
if not histpath: if not histpath:
self.log("no histpath for [{}]".format(ptop)) self.log("no histpath for %r" % (ptop,))
return None return None
tpath = thumb_path(histpath, rem, mtime, fmt, self.fmt_ffa) tpath = thumb_path(histpath, rem, mtime, fmt, self.fmt_ffa)

View file

@ -239,7 +239,7 @@ class ThumbSrv(object):
def get(self, ptop: str, rem: str, mtime: float, fmt: str) -> Optional[str]: def get(self, ptop: str, rem: str, mtime: float, fmt: str) -> Optional[str]:
histpath = self.asrv.vfs.histtab.get(ptop) histpath = self.asrv.vfs.histtab.get(ptop)
if not histpath: if not histpath:
self.log("no histpath for [{}]".format(ptop)) self.log("no histpath for %r" % (ptop,))
return None return None
tpath = thumb_path(histpath, rem, mtime, fmt, self.fmt_ffa) tpath = thumb_path(histpath, rem, mtime, fmt, self.fmt_ffa)
@ -249,7 +249,7 @@ class ThumbSrv(object):
with self.mutex: with self.mutex:
try: try:
self.busy[tpath].append(cond) self.busy[tpath].append(cond)
self.log("joined waiting room for %s" % (tpath,)) self.log("joined waiting room for %r" % (tpath,))
except: except:
thdir = os.path.dirname(tpath) thdir = os.path.dirname(tpath)
bos.makedirs(os.path.join(thdir, "w")) bos.makedirs(os.path.join(thdir, "w"))
@ -266,11 +266,11 @@ class ThumbSrv(object):
allvols = list(self.asrv.vfs.all_vols.values()) allvols = list(self.asrv.vfs.all_vols.values())
vn = next((x for x in allvols if x.realpath == ptop), None) vn = next((x for x in allvols if x.realpath == ptop), None)
if not vn: if not vn:
self.log("ptop [{}] not in {}".format(ptop, allvols), 3) self.log("ptop %r not in %s" % (ptop, allvols), 3)
vn = self.asrv.vfs.all_aps[0][1] vn = self.asrv.vfs.all_aps[0][1]
self.q.put((abspath, tpath, fmt, vn)) self.q.put((abspath, tpath, fmt, vn))
self.log("conv {} :{} \033[0m{}".format(tpath, fmt, abspath), c=6) self.log("conv %r :%s \033[0m%r" % (tpath, fmt, abspath), 6)
while not self.stopping: while not self.stopping:
with self.mutex: with self.mutex:
@ -375,8 +375,8 @@ class ThumbSrv(object):
fun(ap_unpk, ttpath, fmt, vn) fun(ap_unpk, ttpath, fmt, vn)
break break
except Exception as ex: except Exception as ex:
msg = "{} could not create thumbnail of {}\n{}" msg = "%s could not create thumbnail of %r\n%s"
msg = msg.format(fun.__name__, abspath, min_ex()) msg = msg % (fun.__name__, abspath, min_ex())
c: Union[str, int] = 1 if "<Signals.SIG" in msg else "90" c: Union[str, int] = 1 if "<Signals.SIG" in msg else "90"
self.log(msg, c) self.log(msg, c)
if getattr(ex, "returncode", 0) != 321: if getattr(ex, "returncode", 0) != 321:

View file

@ -136,7 +136,7 @@ class U2idx(object):
ptop = vn.realpath ptop = vn.realpath
histpath = self.asrv.vfs.histtab.get(ptop) histpath = self.asrv.vfs.histtab.get(ptop)
if not histpath: if not histpath:
self.log("no histpath for [{}]".format(ptop)) self.log("no histpath for %r" % (ptop,))
return None return None
db_path = os.path.join(histpath, "up2k.db") db_path = os.path.join(histpath, "up2k.db")
@ -151,7 +151,7 @@ class U2idx(object):
db = sqlite3.connect(uri, timeout=2, uri=True, check_same_thread=False) db = sqlite3.connect(uri, timeout=2, uri=True, check_same_thread=False)
cur = db.cursor() cur = db.cursor()
cur.execute('pragma table_info("up")').fetchone() cur.execute('pragma table_info("up")').fetchone()
self.log("ro: {}".format(db_path)) self.log("ro: %r" % (db_path,))
except: except:
self.log("could not open read-only: {}\n{}".format(uri, min_ex())) self.log("could not open read-only: {}\n{}".format(uri, min_ex()))
# may not fail until the pragma so unset it # may not fail until the pragma so unset it
@ -161,7 +161,7 @@ class U2idx(object):
# on windows, this steals the write-lock from up2k.deferred_init -- # on windows, this steals the write-lock from up2k.deferred_init --
# seen on win 10.0.17763.2686, py 3.10.4, sqlite 3.37.2 # seen on win 10.0.17763.2686, py 3.10.4, sqlite 3.37.2
cur = sqlite3.connect(db_path, timeout=2, check_same_thread=False).cursor() cur = sqlite3.connect(db_path, timeout=2, check_same_thread=False).cursor()
self.log("opened {}".format(db_path)) self.log("opened %r" % (db_path,))
self.cur[ptop] = cur self.cur[ptop] = cur
return cur return cur

View file

@ -794,7 +794,7 @@ class Up2k(object):
if ccd != cd: if ccd != cd:
continue continue
self.log("xiu: {}# {}".format(len(wrfs), cmd)) self.log("xiu: %d# %r" % (len(wrfs), cmd))
runihook(self.log, cmd, vol, ups) runihook(self.log, cmd, vol, ups)
def _vis_job_progress(self, job: dict[str, Any]) -> str: def _vis_job_progress(self, job: dict[str, Any]) -> str:
@ -1060,7 +1060,7 @@ class Up2k(object):
"""mutex(main,reg) me""" """mutex(main,reg) me"""
histpath = self.vfs.histtab.get(ptop) histpath = self.vfs.histtab.get(ptop)
if not histpath: if not histpath:
self.log("no histpath for [{}]".format(ptop)) self.log("no histpath for %r" % (ptop,))
return None return None
db_path = os.path.join(histpath, "up2k.db") db_path = os.path.join(histpath, "up2k.db")
@ -1154,7 +1154,7 @@ class Up2k(object):
job["poke"] = time.time() job["poke"] = time.time()
job["busy"] = {} job["busy"] = {}
else: else:
self.log("ign deleted file in snap: [{}]".format(fp)) self.log("ign deleted file in snap: %r" % (fp,))
if not n4g: if not n4g:
rm.append(k) rm.append(k)
continue continue
@ -1386,12 +1386,12 @@ class Up2k(object):
xvol: bool, xvol: bool,
) -> tuple[int, int, int]: ) -> tuple[int, int, int]:
if xvol and not rcdir.startswith(top): if xvol and not rcdir.startswith(top):
self.log("skip xvol: [{}] -> [{}]".format(cdir, rcdir), 6) self.log("skip xvol: %r -> %r" % (cdir, rcdir), 6)
return 0, 0, 0 return 0, 0, 0
if rcdir in seen: if rcdir in seen:
t = "bailing from symlink loop,\n prev: {}\n curr: {}\n from: {}" t = "bailing from symlink loop,\n prev: %r\n curr: %r\n from: %r"
self.log(t.format(seen[-1], rcdir, cdir), 3) self.log(t % (seen[-1], rcdir, cdir), 3)
return 0, 0, 0 return 0, 0, 0
# total-files-added, total-num-files, recursive-size # total-files-added, total-num-files, recursive-size
@ -1447,7 +1447,7 @@ class Up2k(object):
and inf.st_dev != dev and inf.st_dev != dev
and not (ANYWIN and bos.stat(rap).st_dev == dev) and not (ANYWIN and bos.stat(rap).st_dev == dev)
): ):
self.log("skip xdev {}->{}: {}".format(dev, inf.st_dev, abspath), 6) self.log("skip xdev %s->%s: %r" % (dev, inf.st_dev, abspath), 6)
continue continue
if abspath in excl or rap in excl: if abspath in excl or rap in excl:
unreg.append(rp) unreg.append(rp)
@ -1476,10 +1476,10 @@ class Up2k(object):
tnf += i2 tnf += i2
rsz += i3 rsz += i3
except: except:
t = "failed to index subdir [{}]:\n{}" t = "failed to index subdir %r:\n%s"
self.log(t.format(abspath, min_ex()), c=1) self.log(t % (abspath, min_ex()), 1)
elif not stat.S_ISREG(inf.st_mode): elif not stat.S_ISREG(inf.st_mode):
self.log("skip type-0%o file [%s]" % (inf.st_mode, abspath)) self.log("skip type-0%o file %r" % (inf.st_mode, abspath))
else: else:
# self.log("file: {}".format(abspath)) # self.log("file: {}".format(abspath))
if rp.endswith(".PARTIAL") and time.time() - lmod < 60: if rp.endswith(".PARTIAL") and time.time() - lmod < 60:
@ -1562,7 +1562,7 @@ class Up2k(object):
db.c.execute("insert into cv values (?,?,?)", (crd, cdn, cv)) db.c.execute("insert into cv values (?,?,?)", (crd, cdn, cv))
db.n += 1 db.n += 1
except Exception as ex: except Exception as ex:
self.log("cover {}/{} failed: {}".format(rd, cv, ex), 6) self.log("cover %r/%r failed: %s" % (rd, cv, ex), 6)
seen_files = set([x[2] for x in files]) # for dropcheck seen_files = set([x[2] for x in files]) # for dropcheck
for sz, lmod, fn in files: for sz, lmod, fn in files:
@ -1584,9 +1584,9 @@ class Up2k(object):
self.pp.n -= 1 self.pp.n -= 1
dw, dts, dsz, ip, at = in_db[0] dw, dts, dsz, ip, at = in_db[0]
if len(in_db) > 1: if len(in_db) > 1:
t = "WARN: multiple entries: [{}] => [{}] |{}|\n{}" t = "WARN: multiple entries: %r => %r |%d|\n%r"
rep_db = "\n".join([repr(x) for x in in_db]) rep_db = "\n".join([repr(x) for x in in_db])
self.log(t.format(top, rp, len(in_db), rep_db)) self.log(t % (top, rp, len(in_db), rep_db))
dts = -1 dts = -1
if fat32 and abs(dts - lmod) == 1: if fat32 and abs(dts - lmod) == 1:
@ -1595,10 +1595,8 @@ class Up2k(object):
if dts == lmod and dsz == sz and (nohash or dw[0] != "#" or not sz): if dts == lmod and dsz == sz and (nohash or dw[0] != "#" or not sz):
continue continue
t = "reindex [{}] => [{}] mtime({}/{}) size({}/{})".format( t = "reindex %r => %r mtime(%s/%s) size(%s/%s)"
top, rp, dts, lmod, dsz, sz self.log(t % (top, rp, dts, lmod, dsz, sz))
)
self.log(t)
self.db_rm(db.c, rd, fn, 0) self.db_rm(db.c, rd, fn, 0)
tfa += 1 tfa += 1
db.n += 1 db.n += 1
@ -1614,14 +1612,14 @@ class Up2k(object):
wark = up2k_wark_from_metadata(self.salt, sz, lmod, rd, fn) wark = up2k_wark_from_metadata(self.salt, sz, lmod, rd, fn)
else: else:
if sz > 1024 * 1024: if sz > 1024 * 1024:
self.log("file: {}".format(abspath)) self.log("file: %r" % (abspath,))
try: try:
hashes, _ = self._hashlist_from_file( hashes, _ = self._hashlist_from_file(
abspath, "a{}, ".format(self.pp.n) abspath, "a{}, ".format(self.pp.n)
) )
except Exception as ex: except Exception as ex:
self.log("hash: {} @ [{}]".format(repr(ex), abspath)) self.log("hash: %r @ %r" % (ex, abspath))
continue continue
if not hashes: if not hashes:
@ -1667,8 +1665,8 @@ class Up2k(object):
assert erd_erd # type: ignore # !rm assert erd_erd # type: ignore # !rm
if n: if n:
t = "forgetting {} shadowed autoindexed files in [{}] > [{}]" t = "forgetting %d shadowed autoindexed files in %r > %r"
self.log(t.format(n, top, sh_rd)) self.log(t % (n, top, sh_rd))
q = "delete from dh where (d = ? or d like ?||'/%')" q = "delete from dh where (d = ? or d like ?||'/%')"
db.c.execute(q, erd_erd) db.c.execute(q, erd_erd)
@ -1865,7 +1863,7 @@ class Up2k(object):
stl = bos.lstat(abspath) stl = bos.lstat(abspath)
st = bos.stat(abspath) if stat.S_ISLNK(stl.st_mode) else stl st = bos.stat(abspath) if stat.S_ISLNK(stl.st_mode) else stl
except Exception as ex: except Exception as ex:
self.log("missing file: %s" % (abspath,), 3) self.log("missing file: %r" % (abspath,), 3)
f404.append((drd, dfn, w)) f404.append((drd, dfn, w))
continue continue
@ -1876,12 +1874,12 @@ class Up2k(object):
w2 = up2k_wark_from_metadata(self.salt, sz2, mt2, rd, fn) w2 = up2k_wark_from_metadata(self.salt, sz2, mt2, rd, fn)
else: else:
if sz2 > 1024 * 1024 * 32: if sz2 > 1024 * 1024 * 32:
self.log("file: {}".format(abspath)) self.log("file: %r" % (abspath,))
try: try:
hashes, _ = self._hashlist_from_file(abspath, pf) hashes, _ = self._hashlist_from_file(abspath, pf)
except Exception as ex: except Exception as ex:
self.log("hash: {} @ [{}]".format(repr(ex), abspath)) self.log("hash: %r @ %r" % (ex, abspath))
continue continue
if not hashes: if not hashes:
@ -1901,9 +1899,8 @@ class Up2k(object):
rewark.append((drd, dfn, w2, sz2, mt2)) rewark.append((drd, dfn, w2, sz2, mt2))
t = "hash mismatch: {}\n db: {} ({} byte, {})\n fs: {} ({} byte, {})" t = "hash mismatch: %r\n db: %s (%d byte, %d)\n fs: %s (%d byte, %d)"
t = t.format(abspath, w, sz, mt, w2, sz2, mt2) self.log(t % (abspath, w, sz, mt, w2, sz2, mt2), 1)
self.log(t, 1)
if e2vp and (rewark or f404): if e2vp and (rewark or f404):
self.hub.retcode = 1 self.hub.retcode = 1
@ -2451,7 +2448,7 @@ class Up2k(object):
q.task_done() q.task_done()
def _log_tag_err(self, parser: Any, abspath: str, ex: Any) -> None: def _log_tag_err(self, parser: Any, abspath: str, ex: Any) -> None:
msg = "{} failed to read tags from {}:\n{}".format(parser, abspath, ex) msg = "%s failed to read tags from %r:\n%s" % (parser, abspath, ex)
self.log(msg.lstrip(), c=1 if "<Signals.SIG" in msg else 3) self.log(msg.lstrip(), c=1 if "<Signals.SIG" in msg else 3)
def _tagscan_file( def _tagscan_file(
@ -2991,11 +2988,11 @@ class Up2k(object):
job = rj job = rj
break break
else: else:
self.log("asserting contents of %s" % (orig_ap,)) self.log("asserting contents of %r" % (orig_ap,))
hashes2, st = self._hashlist_from_file(orig_ap) hashes2, st = self._hashlist_from_file(orig_ap)
wark2 = up2k_wark_from_hashlist(self.salt, st.st_size, hashes2) wark2 = up2k_wark_from_hashlist(self.salt, st.st_size, hashes2)
if dwark != wark2: if dwark != wark2:
t = "will not dedup (fs index desync): fs=%s, db=%s, file: %s\n%s" t = "will not dedup (fs index desync): fs=%s, db=%s, file: %r\n%s"
self.log(t % (wark2, dwark, orig_ap, rj)) self.log(t % (wark2, dwark, orig_ap, rj))
lost.append(dupe[3:]) lost.append(dupe[3:])
continue continue
@ -3013,8 +3010,8 @@ class Up2k(object):
if lost: if lost:
c2 = None c2 = None
for cur, dp_dir, dp_fn in lost: for cur, dp_dir, dp_fn in lost:
t = "forgetting desynced db entry: /{}" t = "forgetting desynced db entry: %r"
self.log(t.format(vjoin(vjoin(vfs.vpath, dp_dir), dp_fn))) self.log(t % ("/" + vjoin(vjoin(vfs.vpath, dp_dir), dp_fn)))
self.db_rm(cur, dp_dir, dp_fn, cj["size"]) self.db_rm(cur, dp_dir, dp_fn, cj["size"])
if c2 and c2 != cur: if c2 and c2 != cur:
c2.connection.commit() c2.connection.commit()
@ -3043,8 +3040,8 @@ class Up2k(object):
except: except:
# missing; restart # missing; restart
if not self.args.nw and not n4g: if not self.args.nw and not n4g:
t = "forgetting deleted partial upload at {}" t = "forgetting deleted partial upload at %r"
self.log(t.format(path)) self.log(t % (path,))
del reg[wark] del reg[wark]
break break
@ -3055,19 +3052,25 @@ class Up2k(object):
pass pass
elif st.st_size != rj["size"]: elif st.st_size != rj["size"]:
t = "will not dedup (fs index desync): {}, size fs={} db={}, mtime fs={} db={}, file: {}\n{}" t = "will not dedup (fs index desync): %s, size fs=%d db=%d, mtime fs=%d db=%d, file: %r\n%s"
t = t.format( t = t % (
wark, st.st_size, rj["size"], st.st_mtime, rj["lmod"], path, rj wark,
st.st_size,
rj["size"],
st.st_mtime,
rj["lmod"],
path,
rj,
) )
self.log(t) self.log(t)
del reg[wark] del reg[wark]
elif inc_ap != orig_ap and not data_ok and "done" in reg[wark]: elif inc_ap != orig_ap and not data_ok and "done" in reg[wark]:
self.log("asserting contents of %s" % (orig_ap,)) self.log("asserting contents of %r" % (orig_ap,))
hashes2, _ = self._hashlist_from_file(orig_ap) hashes2, _ = self._hashlist_from_file(orig_ap)
wark2 = up2k_wark_from_hashlist(self.salt, st.st_size, hashes2) wark2 = up2k_wark_from_hashlist(self.salt, st.st_size, hashes2)
if wark != wark2: if wark != wark2:
t = "will not dedup (fs index desync): fs=%s, idx=%s, file: %s\n%s" t = "will not dedup (fs index desync): fs=%s, idx=%s, file: %r\n%s"
self.log(t % (wark2, wark, orig_ap, rj)) self.log(t % (wark2, wark, orig_ap, rj))
del reg[wark] del reg[wark]
@ -3084,7 +3087,7 @@ class Up2k(object):
vsrc = djoin(job["vtop"], job["prel"], job["name"]) vsrc = djoin(job["vtop"], job["prel"], job["name"])
vsrc = vsrc.replace("\\", "/") # just for prints anyways vsrc = vsrc.replace("\\", "/") # just for prints anyways
if "done" not in job: if "done" not in job:
self.log("unfinished:\n {0}\n {1}".format(src, dst)) self.log("unfinished:\n %r\n %r" % (src, dst))
err = "partial upload exists at a different location; please resume uploading here instead:\n" err = "partial upload exists at a different location; please resume uploading here instead:\n"
err += "/" + quotep(vsrc) + " " err += "/" + quotep(vsrc) + " "
@ -3101,7 +3104,7 @@ class Up2k(object):
raise Pebkac(422, err) raise Pebkac(422, err)
elif "nodupe" in vfs.flags: elif "nodupe" in vfs.flags:
self.log("dupe-reject:\n {0}\n {1}".format(src, dst)) self.log("dupe-reject:\n %r\n %r" % (src, dst))
err = "upload rejected, file already exists:\n" err = "upload rejected, file already exists:\n"
err += "/" + quotep(vsrc) + " " err += "/" + quotep(vsrc) + " "
raise Pebkac(409, err) raise Pebkac(409, err)
@ -3163,7 +3166,7 @@ class Up2k(object):
"", "",
) )
if not hr: if not hr:
t = "upload blocked by xbu server config: %s" % (dst,) t = "upload blocked by xbu server config: %r" % (dst,)
self.log(t, 1) self.log(t, 1)
raise Pebkac(403, t) raise Pebkac(403, t)
if hr.get("reloc"): if hr.get("reloc"):
@ -3304,7 +3307,7 @@ class Up2k(object):
times = (int(time.time()), int(cj["lmod"])) times = (int(time.time()), int(cj["lmod"]))
bos.utime(ap, times, False) bos.utime(ap, times, False)
self.log("touched %s from %d to %d" % (ap, job["lmod"], cj["lmod"])) self.log("touched %r from %d to %d" % (ap, job["lmod"], cj["lmod"]))
except Exception as ex: except Exception as ex:
self.log("umod failed, %r" % (ex,), 3) self.log("umod failed, %r" % (ex,), 3)
@ -3319,7 +3322,7 @@ class Up2k(object):
fp = djoin(fdir, fname) fp = djoin(fdir, fname)
if job.get("replace") and bos.path.exists(fp): if job.get("replace") and bos.path.exists(fp):
self.log("replacing existing file at {}".format(fp)) self.log("replacing existing file at %r" % (fp,))
cur = None cur = None
ptop = job["ptop"] ptop = job["ptop"]
vf = self.flags.get(ptop) or {} vf = self.flags.get(ptop) or {}
@ -3362,9 +3365,9 @@ class Up2k(object):
raise Exception(t % (src, fsrc, dst)) raise Exception(t % (src, fsrc, dst))
if verbose: if verbose:
t = "linking dupe:\n point-to: {0}\n link-loc: {1}" t = "linking dupe:\n point-to: {0!r}\n link-loc: {1!r}"
if fsrc: if fsrc:
t += "\n data-src: {2}" t += "\n data-src: {2!r}"
self.log(t.format(src, dst, fsrc)) self.log(t.format(src, dst, fsrc))
if self.args.nw: if self.args.nw:
@ -3434,7 +3437,7 @@ class Up2k(object):
elif fsrc and bos.path.isfile(fsrc): elif fsrc and bos.path.isfile(fsrc):
csrc = fsrc csrc = fsrc
else: else:
t = "BUG: no valid sources to link from! orig(%s) fsrc(%s) link(%s)" t = "BUG: no valid sources to link from! orig(%r) fsrc(%r) link(%r)"
self.log(t, 1) self.log(t, 1)
raise Exception(t % (src, fsrc, dst)) raise Exception(t % (src, fsrc, dst))
shutil.copy2(fsenc(csrc), fsenc(dst)) shutil.copy2(fsenc(csrc), fsenc(dst))
@ -3612,15 +3615,12 @@ class Up2k(object):
atomic_move(self.log, src, dst, vflags) atomic_move(self.log, src, dst, vflags)
times = (int(time.time()), int(job["lmod"])) times = (int(time.time()), int(job["lmod"]))
self.log( t = "no more chunks, setting times %s (%d) on %r"
"no more chunks, setting times {} ({}) on {}".format( self.log(t % (times, bos.path.getsize(dst), dst))
times, bos.path.getsize(dst), dst
)
)
try: try:
bos.utime(dst, times) bos.utime(dst, times)
except: except:
self.log("failed to utime ({}, {})".format(dst, times)) self.log("failed to utime (%r, %s)" % (dst, times))
zs = "prel name lmod size ptop vtop wark dwrk host user addr" zs = "prel name lmod size ptop vtop wark dwrk host user addr"
z2 = [job[x] for x in zs.split()] z2 = [job[x] for x in zs.split()]
@ -3985,7 +3985,7 @@ class Up2k(object):
vpath_dir = vsplit(vpath)[0] vpath_dir = vsplit(vpath)[0]
g = [(vn, voldir, vpath_dir, adir, [(fn, 0)], [], {})] # type: ignore g = [(vn, voldir, vpath_dir, adir, [(fn, 0)], [], {})] # type: ignore
else: else:
self.log("rm: skip type-0%o file [%s]" % (st.st_mode, atop)) self.log("rm: skip type-0%o file %r" % (st.st_mode, atop))
return 0, [], [] return 0, [], []
xbd = vn.flags.get("xbd") xbd = vn.flags.get("xbd")
@ -4009,7 +4009,7 @@ class Up2k(object):
volpath = ("%s/%s" % (vrem, fn)).strip("/") volpath = ("%s/%s" % (vrem, fn)).strip("/")
vpath = ("%s/%s" % (dbv.vpath, volpath)).strip("/") vpath = ("%s/%s" % (dbv.vpath, volpath)).strip("/")
self.log("rm %s\n %s" % (vpath, abspath)) self.log("rm %r\n %r" % (vpath, abspath))
if not unpost: if not unpost:
# recursion-only sanchk # recursion-only sanchk
_ = dbv.get(volpath, uname, *permsets[0]) _ = dbv.get(volpath, uname, *permsets[0])
@ -4032,8 +4032,8 @@ class Up2k(object):
time.time(), time.time(),
"", "",
): ):
t = "delete blocked by xbd server config: {}" t = "delete blocked by xbd server config: %r"
self.log(t.format(abspath), 1) self.log(t % (abspath,), 1)
continue continue
n_files += 1 n_files += 1
@ -4127,7 +4127,7 @@ class Up2k(object):
svpf = "/".join(x for x in [dbv.vpath, vrem, fn[0]] if x) svpf = "/".join(x for x in [dbv.vpath, vrem, fn[0]] if x)
if not svpf.startswith(svp + "/"): # assert if not svpf.startswith(svp + "/"): # assert
self.log(min_ex(), 1) self.log(min_ex(), 1)
t = "cp: bug at %s, top %s%s" t = "cp: bug at %r, top %r%s"
raise Pebkac(500, t % (svpf, svp, SEESLOG)) raise Pebkac(500, t % (svpf, svp, SEESLOG))
dvpf = dvp + svpf[len(svp) :] dvpf = dvp + svpf[len(svp) :]
@ -4167,7 +4167,7 @@ class Up2k(object):
except: except:
pass # broken symlink; keep as-is pass # broken symlink; keep as-is
elif not stat.S_ISREG(st.st_mode): elif not stat.S_ISREG(st.st_mode):
self.log("skipping type-0%o file [%s]" % (st.st_mode, sabs)) self.log("skipping type-0%o file %r" % (st.st_mode, sabs))
return "" return ""
else: else:
is_link = False is_link = False
@ -4195,7 +4195,7 @@ class Up2k(object):
time.time(), time.time(),
"", "",
): ):
t = "copy blocked by xbr server config: {}".format(svp) t = "copy blocked by xbr server config: %r" % (svp,)
self.log(t, 1) self.log(t, 1)
raise Pebkac(405, t) raise Pebkac(405, t)
@ -4232,7 +4232,7 @@ class Up2k(object):
) )
curs.add(c2) curs.add(c2)
else: else:
self.log("not found in src db: [{}]".format(svp)) self.log("not found in src db: %r" % (svp,))
try: try:
if is_link and st != stl: if is_link and st != stl:
@ -4249,7 +4249,7 @@ class Up2k(object):
if ex.errno != errno.EXDEV: if ex.errno != errno.EXDEV:
raise raise
self.log("using plain copy (%s):\n %s\n %s" % (ex.strerror, sabs, dabs)) self.log("using plain copy (%s):\n %r\n %r" % (ex.strerror, sabs, dabs))
b1, b2 = fsenc(sabs), fsenc(dabs) b1, b2 = fsenc(sabs), fsenc(dabs)
is_link = os.path.islink(b1) # due to _relink is_link = os.path.islink(b1) # due to _relink
try: try:
@ -4349,7 +4349,7 @@ class Up2k(object):
svpf = "/".join(x for x in [dbv.vpath, vrem, fn[0]] if x) svpf = "/".join(x for x in [dbv.vpath, vrem, fn[0]] if x)
if not svpf.startswith(svp + "/"): # assert if not svpf.startswith(svp + "/"): # assert
self.log(min_ex(), 1) self.log(min_ex(), 1)
t = "mv: bug at %s, top %s%s" t = "mv: bug at %r, top %r%s"
raise Pebkac(500, t % (svpf, svp, SEESLOG)) raise Pebkac(500, t % (svpf, svp, SEESLOG))
dvpf = dvp + svpf[len(svp) :] dvpf = dvp + svpf[len(svp) :]
@ -4368,7 +4368,7 @@ class Up2k(object):
for ap in reversed(zsl): for ap in reversed(zsl):
if not ap.startswith(sabs): if not ap.startswith(sabs):
self.log(min_ex(), 1) self.log(min_ex(), 1)
t = "mv_d: bug at %s, top %s%s" t = "mv_d: bug at %r, top %r%s"
raise Pebkac(500, t % (ap, sabs, SEESLOG)) raise Pebkac(500, t % (ap, sabs, SEESLOG))
rem = ap[len(sabs) :].replace(os.sep, "/").lstrip("/") rem = ap[len(sabs) :].replace(os.sep, "/").lstrip("/")
@ -4439,7 +4439,7 @@ class Up2k(object):
time.time(), time.time(),
"", "",
): ):
t = "move blocked by xbr server config: {}".format(svp) t = "move blocked by xbr server config: %r" % (svp,)
self.log(t, 1) self.log(t, 1)
raise Pebkac(405, t) raise Pebkac(405, t)
@ -4449,8 +4449,8 @@ class Up2k(object):
if is_dirlink: if is_dirlink:
dlabs = absreal(sabs) dlabs = absreal(sabs)
t = "moving symlink from [{}] to [{}], target [{}]" t = "moving symlink from %r to %r, target %r"
self.log(t.format(sabs, dabs, dlabs)) self.log(t % (sabs, dabs, dlabs))
mt = bos.path.getmtime(sabs, False) mt = bos.path.getmtime(sabs, False)
wunlink(self.log, sabs, svn.flags) wunlink(self.log, sabs, svn.flags)
self._symlink(dlabs, dabs, dvn.flags, False, lmod=mt) self._symlink(dlabs, dabs, dvn.flags, False, lmod=mt)
@ -4522,7 +4522,7 @@ class Up2k(object):
) )
curs.add(c2) curs.add(c2)
else: else:
self.log("not found in src db: [{}]".format(svp)) self.log("not found in src db: %r" % (svp,))
try: try:
if is_xvol and has_dupes: if is_xvol and has_dupes:
@ -4543,7 +4543,7 @@ class Up2k(object):
if ex.errno != errno.EXDEV: if ex.errno != errno.EXDEV:
raise raise
self.log("using copy+delete (%s):\n %s\n %s" % (ex.strerror, sabs, dabs)) self.log("using copy+delete (%s):\n %r\n %r" % (ex.strerror, sabs, dabs))
b1, b2 = fsenc(sabs), fsenc(dabs) b1, b2 = fsenc(sabs), fsenc(dabs)
is_link = os.path.islink(b1) # due to _relink is_link = os.path.islink(b1) # due to _relink
try: try:
@ -4651,7 +4651,7 @@ class Up2k(object):
""" """
srd, sfn = vsplit(vrem) srd, sfn = vsplit(vrem)
has_dupes = False has_dupes = False
self.log("forgetting {}".format(vrem)) self.log("forgetting %r" % (vrem,))
if wark and cur: if wark and cur:
self.log("found {} in db".format(wark)) self.log("found {} in db".format(wark))
if drop_tags: if drop_tags:
@ -4727,7 +4727,7 @@ class Up2k(object):
dvrem = vjoin(rd, fn).strip("/") dvrem = vjoin(rd, fn).strip("/")
if ptop != sptop or srem != dvrem: if ptop != sptop or srem != dvrem:
dupes.append([ptop, dvrem]) dupes.append([ptop, dvrem])
self.log("found {} dupe: [{}] {}".format(wark, ptop, dvrem)) self.log("found %s dupe: %r %r" % (wark, ptop, dvrem))
if not dupes: if not dupes:
return 0 return 0
@ -4740,7 +4740,7 @@ class Up2k(object):
d = links if bos.path.islink(ap) else full d = links if bos.path.islink(ap) else full
d[ap] = (ptop, vp) d[ap] = (ptop, vp)
except: except:
self.log("relink: not found: [{}]".format(ap)) self.log("relink: not found: %r" % (ap,))
# self.log("full:\n" + "\n".join(" {:90}: {}".format(*x) for x in full.items())) # self.log("full:\n" + "\n".join(" {:90}: {}".format(*x) for x in full.items()))
# self.log("links:\n" + "\n".join(" {:90}: {}".format(*x) for x in links.items())) # self.log("links:\n" + "\n".join(" {:90}: {}".format(*x) for x in links.items()))
@ -4748,7 +4748,7 @@ class Up2k(object):
# deleting final remaining full copy; swap it with a symlink # deleting final remaining full copy; swap it with a symlink
slabs = list(sorted(links.keys()))[0] slabs = list(sorted(links.keys()))[0]
ptop, rem = links.pop(slabs) ptop, rem = links.pop(slabs)
self.log("linkswap [{}] and [{}]".format(sabs, slabs)) self.log("linkswap %r and %r" % (sabs, slabs))
mt = bos.path.getmtime(slabs, False) mt = bos.path.getmtime(slabs, False)
flags = self.flags.get(ptop) or {} flags = self.flags.get(ptop) or {}
atomic_move(self.log, sabs, slabs, flags) atomic_move(self.log, sabs, slabs, flags)
@ -4783,7 +4783,7 @@ class Up2k(object):
zs = absreal(alink) zs = absreal(alink)
if ldst != zs: if ldst != zs:
t = "relink because computed != actual destination:\n %s\n %s" t = "relink because computed != actual destination:\n %r\n %r"
self.log(t % (ldst, zs), 3) self.log(t % (ldst, zs), 3)
ldst = zs ldst = zs
faulty = True faulty = True
@ -4798,7 +4798,7 @@ class Up2k(object):
t = "relink because symlink verification failed: %s; %r" t = "relink because symlink verification failed: %s; %r"
self.log(t % (ex, ex), 3) self.log(t % (ex, ex), 3)
self.log("relinking [%s] to [%s]" % (alink, dabs)) self.log("relinking %r to %r" % (alink, dabs))
flags = self.flags.get(parts[0]) or {} flags = self.flags.get(parts[0]) or {}
try: try:
lmod = bos.path.getmtime(alink, False) lmod = bos.path.getmtime(alink, False)
@ -4913,7 +4913,7 @@ class Up2k(object):
"", "",
) )
if not hr: if not hr:
t = "upload blocked by xbu server config: {}".format(vp_chk) t = "upload blocked by xbu server config: %r" % (vp_chk,)
self.log(t, 1) self.log(t, 1)
raise Pebkac(403, t) raise Pebkac(403, t)
if hr.get("reloc"): if hr.get("reloc"):
@ -4963,7 +4963,7 @@ class Up2k(object):
try: try:
sp.check_call(["fsutil", "sparse", "setflag", abspath]) sp.check_call(["fsutil", "sparse", "setflag", abspath])
except: except:
self.log("could not sparse [{}]".format(abspath), 3) self.log("could not sparse %r" % (abspath,), 3)
relabel = True relabel = True
sprs = False sprs = False
@ -5150,7 +5150,7 @@ class Up2k(object):
self._tag_file(cur, entags, wark, abspath, tags) self._tag_file(cur, entags, wark, abspath, tags)
cur.connection.commit() cur.connection.commit()
self.log("tagged {} ({}+{})".format(abspath, ntags1, len(tags) - ntags1)) self.log("tagged %r (%d+%d)" % (abspath, ntags1, len(tags) - ntags1))
def _hasher(self) -> None: def _hasher(self) -> None:
with self.hashq_mutex: with self.hashq_mutex:
@ -5169,7 +5169,7 @@ class Up2k(object):
if not self._hash_t(task) and self.stop: if not self._hash_t(task) and self.stop:
return return
except Exception as ex: except Exception as ex:
self.log("failed to hash %s: %s" % (task, ex), 1) self.log("failed to hash %r: %s" % (task, ex), 1)
def _hash_t( def _hash_t(
self, task: tuple[str, str, dict[str, Any], str, str, str, float, str, bool] self, task: tuple[str, str, dict[str, Any], str, str, str, float, str, bool]
@ -5181,7 +5181,7 @@ class Up2k(object):
return True return True
abspath = djoin(ptop, rd, fn) abspath = djoin(ptop, rd, fn)
self.log("hashing " + abspath) self.log("hashing %r" % (abspath,))
inf = bos.stat(abspath) inf = bos.stat(abspath)
if not inf.st_size: if not inf.st_size:
wark = up2k_wark_from_metadata( wark = up2k_wark_from_metadata(
@ -5274,7 +5274,7 @@ class Up2k(object):
x = pathmod(self.vfs, "", req_vp, {"vp": fvp, "fn": fn}) x = pathmod(self.vfs, "", req_vp, {"vp": fvp, "fn": fn})
if not x: if not x:
t = "hook_fx(%s): failed to resolve %s based on %s" t = "hook_fx(%s): failed to resolve %r based on %r"
self.log(t % (act, fvp, req_vp)) self.log(t % (act, fvp, req_vp))
continue continue

View file

@ -1024,7 +1024,7 @@ class ProgressPrinter(threading.Thread):
now = time.time() now = time.time()
if msg and now - tp > 10: if msg and now - tp > 10:
tp = now tp = now
self.log("progress: %s" % (msg,), 6) self.log("progress: %r" % (msg,), 6)
if no_stdout: if no_stdout:
continue continue
@ -1626,7 +1626,7 @@ class MultipartParser(object):
(only the fallback non-js uploader relies on these filenames) (only the fallback non-js uploader relies on these filenames)
""" """
for ln in read_header(self.sr, 2, 2592000): for ln in read_header(self.sr, 2, 2592000):
self.log(ln) self.log(repr(ln))
m = self.re_ctype.match(ln) m = self.re_ctype.match(ln)
if m: if m:
@ -1917,11 +1917,11 @@ def gen_filekey_dbg(
if p2 != fspath: if p2 != fspath:
raise Exception() raise Exception()
except: except:
t = "maybe wrong abspath for filekey;\norig: {}\nreal: {}" t = "maybe wrong abspath for filekey;\norig: %r\nreal: %r"
log(t.format(fspath, p2), 1) log(t % (fspath, p2), 1)
t = "fk({}) salt({}) size({}) inode({}) fspath({}) at({})" t = "fk(%s) salt(%s) size(%d) inode(%d) fspath(%r) at(%s)"
log(t.format(ret[:8], salt, fsize, inode, fspath, ctx), 5) log(t % (ret[:8], salt, fsize, inode, fspath, ctx), 5)
return ret return ret
@ -2277,7 +2277,7 @@ def log_reloc(
rem: str, rem: str,
) -> None: ) -> None:
nap, nvp, nfn, (nvn, nrem) = pm nap, nvp, nfn, (nvn, nrem) = pm
t = "reloc %s:\nold ap [%s]\nnew ap [%s\033[36m/%s\033[0m]\nold vp [%s]\nnew vp [%s\033[36m/%s\033[0m]\nold fn [%s]\nnew fn [%s]\nold vfs [%s]\nnew vfs [%s]\nold rem [%s]\nnew rem [%s]" t = "reloc %s:\nold ap %r\nnew ap %r\033[36m/%r\033[0m\nold vp %r\nnew vp %r\033[36m/%r\033[0m\nold fn %r\nnew fn %r\nold vfs %r\nnew vfs %r\nold rem %r\nnew rem %r"
log(t % (re, ap, nap, nfn, vp, nvp, nfn, fn, nfn, vn.vpath, nvn.vpath, rem, nrem)) log(t % (re, ap, nap, nfn, vp, nvp, nfn, fn, nfn, vn.vpath, nvn.vpath, rem, nrem))
@ -2448,7 +2448,7 @@ def lsof(log: "NamedLogger", abspath: str) -> None:
try: try:
rc, so, se = runcmd([b"lsof", b"-R", fsenc(abspath)], timeout=45) rc, so, se = runcmd([b"lsof", b"-R", fsenc(abspath)], timeout=45)
zs = (so.strip() + "\n" + se.strip()).strip() zs = (so.strip() + "\n" + se.strip()).strip()
log("lsof {} = {}\n{}".format(abspath, rc, zs), 3) log("lsof %r = %s\n%s" % (abspath, rc, zs), 3)
except: except:
log("lsof failed; " + min_ex(), 3) log("lsof failed; " + min_ex(), 3)
@ -2484,17 +2484,17 @@ def _fs_mvrm(
for attempt in range(90210): for attempt in range(90210):
try: try:
if ino and os.stat(bsrc).st_ino != ino: if ino and os.stat(bsrc).st_ino != ino:
t = "src inode changed; aborting %s %s" t = "src inode changed; aborting %s %r"
log(t % (act, src), 1) log(t % (act, src), 1)
return False return False
if (dst and not atomic) and os.path.exists(bdst): if (dst and not atomic) and os.path.exists(bdst):
t = "something appeared at dst; aborting rename [%s] ==> [%s]" t = "something appeared at dst; aborting rename %r ==> %r"
log(t % (src, dst), 1) log(t % (src, dst), 1)
return False return False
osfun(*args) osfun(*args)
if attempt: if attempt:
now = time.time() now = time.time()
t = "%sd in %.2f sec, attempt %d: %s" t = "%sd in %.2f sec, attempt %d: %r"
log(t % (act, now - t0, attempt + 1, src)) log(t % (act, now - t0, attempt + 1, src))
return True return True
except OSError as ex: except OSError as ex:
@ -2506,7 +2506,7 @@ def _fs_mvrm(
if not attempt: if not attempt:
if not PY2: if not PY2:
ino = os.stat(bsrc).st_ino ino = os.stat(bsrc).st_ino
t = "%s failed (err.%d); retrying for %d sec: [%s]" t = "%s failed (err.%d); retrying for %d sec: %r"
log(t % (act, ex.errno, maxtime + 0.99, src)) log(t % (act, ex.errno, maxtime + 0.99, src))
time.sleep(chill) time.sleep(chill)
@ -3535,7 +3535,7 @@ def runhook(
log, src, cmd, ap, vp, host, uname, perms, mt, sz, ip, at, txt log, src, cmd, ap, vp, host, uname, perms, mt, sz, ip, at, txt
) )
if log and args.hook_v: if log and args.hook_v:
log("hook(%s) [%s] => \033[32m%s" % (src, cmd, hr), 6) log("hook(%s) %r => \033[32m%s" % (src, cmd, hr), 6)
if not hr: if not hr:
return {} return {}
for k, v in hr.items(): for k, v in hr.items():