Skip to content

Commit

Permalink
try to avoid printing mojibake in logs
Browse files Browse the repository at this point in the history
unprintable and side-effect-inducing paths and names are hex-escaped,
preserving greppability and making log-parsing slightly more okay
  • Loading branch information
9001 committed Dec 18, 2024
1 parent 4c4e48b commit 3051b13
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 186 deletions.
30 changes: 15 additions & 15 deletions copyparty/authsrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def chk_df(self, abspath: str, sz: int, already_written: bool = False) -> None:

df, du, err = get_df(abspath, True)
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.dfv = 0xAAAAAAAAA # 42.6 GiB
else:
Expand Down Expand Up @@ -526,7 +526,7 @@ def get(
"""returns [vfsnode,fs_remainder] if user has the requested permissions"""
if relchk(vpath):
if self.log:
self.log("vfs", "invalid relpath [{}]".format(vpath))
self.log("vfs", "invalid relpath %r @%s" % (vpath, uname))
raise Pebkac(422)

cvpath = undot(vpath)
Expand All @@ -543,11 +543,11 @@ def get(
if req and uname not in d and uname != LEELOO_DALLAS:
if vpath != cvpath and vpath != "." and self.log:
ap = vn.canonical(rem)
t = "{} has no {} in [{}] => [{}] => [{}]"
self.log("vfs", t.format(uname, msg, vpath, cvpath, ap), 6)
t = "%s has no %s in %r => %r => %r"
self.log("vfs", t % (uname, msg, vpath, cvpath, ap), 6)

t = 'you don\'t have %s-access in "/%s" or below "/%s"'
raise Pebkac(err, t % (msg, cvpath, vn.vpath))
t = "you don't have %s-access in %r or below %r"
raise Pebkac(err, t % (msg, "/" + cvpath, "/" + vn.vpath))

return vn, rem

Expand Down Expand Up @@ -693,8 +693,8 @@ def walk(
and fsroot in seen
):
if self.log:
t = "bailing from symlink loop,\n prev: {}\n curr: {}\n from: {}/{}"
self.log("vfs.walk", t.format(seen[-1], fsroot, self.vpath, rem), 3)
t = "bailing from symlink loop,\n prev: %r\n curr: %r\n from: %r / %r"
self.log("vfs.walk", t % (seen[-1], fsroot, self.vpath, rem), 3)
return

if "xdev" in self.flags or "xvol" in self.flags:
Expand Down Expand Up @@ -818,8 +818,8 @@ def chk_ap(self, ap: str, st: Optional[os.stat_result] = None) -> Optional["VFS"

if vdev != st.st_dev:
if self.log:
t = "xdev: {}[{}] => {}[{}]"
self.log("vfs", t.format(vdev, self.realpath, st.st_dev, ap), 3)
t = "xdev: %s[%r] => %s[%r]"
self.log("vfs", t % (vdev, self.realpath, st.st_dev, ap), 3)

return None

Expand All @@ -829,7 +829,7 @@ def chk_ap(self, ap: str, st: Optional[os.stat_result] = None) -> Optional["VFS"
return vn

if self.log:
self.log("vfs", "xvol: [{}]".format(ap), 3)
self.log("vfs", "xvol: %r" % (ap,), 3)

return None

Expand Down Expand Up @@ -914,7 +914,7 @@ def idp_checkin(

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)

if not broker:
Expand Down Expand Up @@ -1568,7 +1568,7 @@ def _reload(self, verbosity: int = 9) -> None:
continue

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))

if s_pw:
Expand Down Expand Up @@ -1765,7 +1765,7 @@ def _reload(self, verbosity: int = 9) -> None:
use = True
try:
_ = float(zs)
zs = "%sg" % (zs)
zs = "%sg" % (zs,)
except:
pass
lim.dfl = unhumanize(zs)
Expand Down Expand Up @@ -2538,7 +2538,7 @@ def setup_chpw(self, acct: dict[str, str]) -> None:
return

elif self.args.chpw_v == 2:
t = "chpw: %d changed" % (len(uok))
t = "chpw: %d changed" % (len(uok),)
if urst:
t += ", \033[0munchanged:\033[35m %s" % (", ".join(list(urst)))

Expand Down
8 changes: 4 additions & 4 deletions copyparty/fsutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ def get(self, path: str) -> str:
self.cache = {}

fs = "ext4"
msg = "failed to determine filesystem at [{}]; assuming {}\n{}"
msg = "failed to determine filesystem at %r; assuming %s\n%s"

if ANYWIN:
fs = "vfat"
try:
path = self._winpath(path)
except:
self.log(msg.format(path, fs, min_ex()), 3)
self.log(msg % (path, fs, min_ex()), 3)
return fs

path = undot(path)
Expand All @@ -61,11 +61,11 @@ def get(self, path: str) -> str:
try:
fs = self.get_w32(path) if ANYWIN else self.get_unix(path)
except:
self.log(msg.format(path, fs, min_ex()), 3)
self.log(msg % (path, fs, min_ex()), 3)

fs = fs.lower()
self.cache[path] = fs
self.log("found {} at {}".format(fs, path))
self.log("found %s at %r" % (fs, path))
return fs

def _winpath(self, path: str) -> str:
Expand Down
Loading

0 comments on commit 3051b13

Please sign in to comment.