sanitize fs-paths in archive error summary

also gets rid of a dumb debug print i forgot
This commit is contained in:
ed 2024-05-30 23:55:37 +00:00
parent 07ea629ca5
commit 5919607ad0
4 changed files with 19 additions and 16 deletions

View file

@ -759,7 +759,6 @@ class HttpCli(object):
is_jinja = True is_jinja = True
if is_jinja: if is_jinja:
print("applying jinja")
with self.conn.hsrv.mutex: with self.conn.hsrv.mutex:
if html not in self.conn.hsrv.j2: if html not in self.conn.hsrv.j2:
j2env = jinja2.Environment() j2env = jinja2.Environment()
@ -3423,7 +3422,7 @@ class HttpCli(object):
bgen = packer( bgen = packer(
self.log, self.log,
self.args, self.asrv,
fgen, fgen,
utf8="utf" in uarg, utf8="utf" in uarg,
pre_crc="crc" in uarg, pre_crc="crc" in uarg,

View file

@ -1,13 +1,13 @@
# coding: utf-8 # coding: utf-8
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import argparse
import re import re
import stat import stat
import tarfile import tarfile
from queue import Queue from queue import Queue
from .authsrv import AuthSrv
from .bos import bos from .bos import bos
from .sutil import StreamArc, errdesc from .sutil import StreamArc, errdesc
from .util import Daemon, fsenc, min_ex from .util import Daemon, fsenc, min_ex
@ -45,12 +45,12 @@ class StreamTar(StreamArc):
def __init__( def __init__(
self, self,
log: "NamedLogger", log: "NamedLogger",
args: argparse.Namespace, asrv: AuthSrv,
fgen: Generator[dict[str, Any], None, None], fgen: Generator[dict[str, Any], None, None],
cmp: str = "", cmp: str = "",
**kwargs: Any **kwargs: Any
): ):
super(StreamTar, self).__init__(log, args, fgen) super(StreamTar, self).__init__(log, asrv, fgen)
self.ci = 0 self.ci = 0
self.co = 0 self.co = 0
@ -148,7 +148,7 @@ class StreamTar(StreamArc):
errors.append((f["vp"], ex)) errors.append((f["vp"], ex))
if errors: if errors:
self.errf, txt = errdesc(errors) self.errf, txt = errdesc(self.asrv.vfs, errors)
self.log("\n".join(([repr(self.errf)] + txt[1:]))) self.log("\n".join(([repr(self.errf)] + txt[1:])))
self.ser(self.errf) self.ser(self.errf)

View file

@ -1,15 +1,15 @@
# coding: utf-8 # coding: utf-8
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import argparse
import os import os
import tempfile import tempfile
from datetime import datetime from datetime import datetime
from .__init__ import CORES from .__init__ import CORES
from .authsrv import AuthSrv, VFS
from .bos import bos from .bos import bos
from .th_cli import ThumbCli from .th_cli import ThumbCli
from .util import UTC, vjoin from .util import UTC, vjoin, vol_san
if True: # pylint: disable=using-constant-test if True: # pylint: disable=using-constant-test
from typing import Any, Generator, Optional from typing import Any, Generator, Optional
@ -21,12 +21,13 @@ class StreamArc(object):
def __init__( def __init__(
self, self,
log: "NamedLogger", log: "NamedLogger",
args: argparse.Namespace, asrv: AuthSrv,
fgen: Generator[dict[str, Any], None, None], fgen: Generator[dict[str, Any], None, None],
**kwargs: Any **kwargs: Any
): ):
self.log = log self.log = log
self.args = args self.asrv = asrv
self.args = asrv.args
self.fgen = fgen self.fgen = fgen
self.stopped = False self.stopped = False
@ -103,15 +104,18 @@ def enthumb(
return f return f
def errdesc(errors: list[tuple[str, str]]) -> tuple[dict[str, Any], list[str]]: def errdesc(vfs: VFS, errors: list[tuple[str, str]]) -> tuple[dict[str, Any], list[str]]:
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: {}".format(fn), "error: {}".format(err), ""])
btxt = "\r\n".join(report).encode("utf-8", "replace")
btxt = vol_san(list(vfs.all_vols.values()), btxt)
with tempfile.NamedTemporaryFile(prefix="copyparty-", delete=False) as tf: with tempfile.NamedTemporaryFile(prefix="copyparty-", delete=False) as tf:
tf_path = tf.name tf_path = tf.name
tf.write("\r\n".join(report).encode("utf-8", "replace")) tf.write(btxt)
dt = datetime.now(UTC).strftime("%Y-%m%d-%H%M%S") dt = datetime.now(UTC).strftime("%Y-%m%d-%H%M%S")

View file

@ -1,12 +1,12 @@
# coding: utf-8 # coding: utf-8
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import argparse
import calendar import calendar
import stat import stat
import time import time
import zlib import zlib
from .authsrv import AuthSrv
from .bos import bos from .bos import bos
from .sutil import StreamArc, errdesc from .sutil import StreamArc, errdesc
from .util import min_ex, sanitize_fn, spack, sunpack, yieldfile from .util import min_ex, sanitize_fn, spack, sunpack, yieldfile
@ -219,13 +219,13 @@ class StreamZip(StreamArc):
def __init__( def __init__(
self, self,
log: "NamedLogger", log: "NamedLogger",
args: argparse.Namespace, asrv: AuthSrv,
fgen: Generator[dict[str, Any], None, None], fgen: Generator[dict[str, Any], None, None],
utf8: bool = False, utf8: bool = False,
pre_crc: bool = False, pre_crc: bool = False,
**kwargs: Any **kwargs: Any
) -> None: ) -> None:
super(StreamZip, self).__init__(log, args, fgen) super(StreamZip, self).__init__(log, asrv, fgen)
self.utf8 = utf8 self.utf8 = utf8
self.pre_crc = pre_crc self.pre_crc = pre_crc
@ -302,7 +302,7 @@ class StreamZip(StreamArc):
mbuf = b"" mbuf = b""
if errors: if errors:
errf, txt = errdesc(errors) errf, txt = errdesc(self.asrv.vfs, errors)
self.log("\n".join(([repr(errf)] + txt[1:]))) self.log("\n".join(([repr(errf)] + txt[1:])))
for x in self.ser(errf): for x in self.ser(errf):
yield x yield x