Skip to content

Commit

Permalink
sanitize fs-paths in archive error summary
Browse files Browse the repository at this point in the history
also gets rid of a dumb debug print i forgot
  • Loading branch information
9001 committed May 30, 2024
1 parent 07ea629 commit 5919607
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
3 changes: 1 addition & 2 deletions copyparty/httpcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,6 @@ def _build_html_head(self, maybe_html: Any, kv: dict[str, Any]) -> bool:
is_jinja = True

if is_jinja:
print("applying jinja")
with self.conn.hsrv.mutex:
if html not in self.conn.hsrv.j2:
j2env = jinja2.Environment()
Expand Down Expand Up @@ -3423,7 +3422,7 @@ def tx_zip(

bgen = packer(
self.log,
self.args,
self.asrv,
fgen,
utf8="utf" in uarg,
pre_crc="crc" in uarg,
Expand Down
8 changes: 4 additions & 4 deletions copyparty/star.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# coding: utf-8
from __future__ import print_function, unicode_literals

import argparse
import re
import stat
import tarfile

from queue import Queue

from .authsrv import AuthSrv
from .bos import bos
from .sutil import StreamArc, errdesc
from .util import Daemon, fsenc, min_ex
Expand Down Expand Up @@ -45,12 +45,12 @@ class StreamTar(StreamArc):
def __init__(
self,
log: "NamedLogger",
args: argparse.Namespace,
asrv: AuthSrv,
fgen: Generator[dict[str, Any], None, None],
cmp: str = "",
**kwargs: Any
):
super(StreamTar, self).__init__(log, args, fgen)
super(StreamTar, self).__init__(log, asrv, fgen)

self.ci = 0
self.co = 0
Expand Down Expand Up @@ -148,7 +148,7 @@ def _gen(self) -> None:
errors.append((f["vp"], ex))

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.ser(self.errf)

Expand Down
16 changes: 10 additions & 6 deletions copyparty/sutil.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# coding: utf-8
from __future__ import print_function, unicode_literals

import argparse
import os
import tempfile
from datetime import datetime

from .__init__ import CORES
from .authsrv import AuthSrv, VFS
from .bos import bos
from .th_cli import ThumbCli
from .util import UTC, vjoin
from .util import UTC, vjoin, vol_san

if True: # pylint: disable=using-constant-test
from typing import Any, Generator, Optional
Expand All @@ -21,12 +21,13 @@ class StreamArc(object):
def __init__(
self,
log: "NamedLogger",
args: argparse.Namespace,
asrv: AuthSrv,
fgen: Generator[dict[str, Any], None, None],
**kwargs: Any
):
self.log = log
self.args = args
self.asrv = asrv
self.args = asrv.args
self.fgen = fgen
self.stopped = False

Expand Down Expand Up @@ -103,15 +104,18 @@ def enthumb(
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:", ""]

for fn, err in errors:
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:
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")

Expand Down
8 changes: 4 additions & 4 deletions copyparty/szip.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# coding: utf-8
from __future__ import print_function, unicode_literals

import argparse
import calendar
import stat
import time
import zlib

from .authsrv import AuthSrv
from .bos import bos
from .sutil import StreamArc, errdesc
from .util import min_ex, sanitize_fn, spack, sunpack, yieldfile
Expand Down Expand Up @@ -219,13 +219,13 @@ class StreamZip(StreamArc):
def __init__(
self,
log: "NamedLogger",
args: argparse.Namespace,
asrv: AuthSrv,
fgen: Generator[dict[str, Any], None, None],
utf8: bool = False,
pre_crc: bool = False,
**kwargs: Any
) -> None:
super(StreamZip, self).__init__(log, args, fgen)
super(StreamZip, self).__init__(log, asrv, fgen)

self.utf8 = utf8
self.pre_crc = pre_crc
Expand Down Expand Up @@ -302,7 +302,7 @@ def gen(self) -> Generator[bytes, None, None]:
mbuf = b""

if errors:
errf, txt = errdesc(errors)
errf, txt = errdesc(self.asrv.vfs, errors)
self.log("\n".join(([repr(errf)] + txt[1:])))
for x in self.ser(errf):
yield x
Expand Down

0 comments on commit 5919607

Please sign in to comment.