From 051c782c288e0dd00f1f457f2841446dea775537 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 10 Jul 2019 01:15:35 +0000 Subject: [PATCH] fix mojibake upload targets (am train, cant sleep) --- copyparty/httpcli.py | 6 +++--- copyparty/svchub.py | 6 +++++- copyparty/web/up2k.js | 13 +++++++------ docs/notes.sh | 15 +++++++++++++++ 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 5ce6ec4e..9fe437b9 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -392,7 +392,7 @@ class HttpCli(object): files.append([sz, sha512_hex]) except Pebkac: - if not nullwrite: + if fn != os.devnull: os.rename(fsenc(fn), fsenc(fn + ".PARTIAL")) raise @@ -443,7 +443,7 @@ class HttpCli(object): ), pre=msg, ) - self.reply(html.encode("utf-8")) + self.reply(html.encode("utf-8", "replace")) self.parser.drop() return True @@ -673,7 +673,7 @@ class HttpCli(object): dirs.extend(files) html = self.conn.tpl_browser.render( - vdir=self.vpath, + vdir=quotep(self.vpath), vpnodes=vpnodes, files=dirs, can_upload=self.writable, diff --git a/copyparty/svchub.py b/copyparty/svchub.py index b901d909..509dbe6c 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -78,7 +78,11 @@ class SvcHub(object): self.next_day = calendar.timegm(dt.utctimetuple()) ts = datetime.utcfromtimestamp(now).strftime("%H:%M:%S.%f")[:-3] - print("\033[36m{} \033[33m{:21} \033[0m{}".format(ts, src, msg)) + msg = "\033[36m{} \033[33m{:21} \033[0m{}".format(ts, src, msg) + try: + print(msg) + except UnicodeEncodeError as ex: + print(msg.encode("utf-8", "replace").decode()) def check_mp_support(self): vmin = sys.version_info[1] diff --git a/copyparty/web/up2k.js b/copyparty/web/up2k.js index 31ea64aa..626def8d 100644 --- a/copyparty/web/up2k.js +++ b/copyparty/web/up2k.js @@ -506,6 +506,7 @@ function up2k_init(have_crypto) { var t = st.todo.hash.shift(); st.busy.hash.push(t); + t.t1 = new Date().getTime(); var nchunk = 0; var chunksize = get_chunksize(t.size); @@ -599,11 +600,11 @@ function up2k_init(have_crypto) { return segm_next(); } - t.t1 = new Date().getTime(); + t.t2 = new Date().getTime(); if (t.n == 0) { // TODO remove - var spd = (t.size / ((t.t1 - t.t0) / 1000.)) / (1024 * 1024.); - alert('{0} ms, {1} MB/s\n'.format(t.t1 - t.t0, spd.toFixed(3)) + t.hash.join('\n')); + var spd = (t.size / ((t.t2 - t.t1) / 1000.)) / (1024 * 1024.); + alert('{0} ms, {1} MB/s\n'.format(t.t2 - t.t1, spd.toFixed(3)) + t.hash.join('\n')); } o('f{0}t'.format(t.n)).innerHTML = 'connecting'; @@ -663,8 +664,8 @@ function up2k_init(have_crypto) { st.busy.handshake.splice(st.busy.handshake.indexOf(t), 1); if (done) { - var spd1 = (t.size / ((t.t1 - t.t0) / 1000.)) / (1024 * 1024.); - var spd2 = (t.size / ((t.t2 - t.t1) / 1000.)) / (1024 * 1024.); + var spd1 = (t.size / ((t.t2 - t.t1) / 1000.)) / (1024 * 1024.); + var spd2 = (t.size / ((t.t3 - t.t2) / 1000.)) / (1024 * 1024.); o('f{0}p'.format(t.n)).innerHTML = 'hash {0}, up {1} MB/s'.format( spd1.toFixed(2), spd2.toFixed(2)); } @@ -724,7 +725,7 @@ function up2k_init(have_crypto) { st.busy.upload.splice(st.busy.upload.indexOf(upt), 1); t.postlist.splice(t.postlist.indexOf(npart), 1); if (t.postlist.length == 0) { - t.t2 = new Date().getTime(); + t.t3 = new Date().getTime(); o('f{0}t'.format(t.n)).innerHTML = 'verifying'; st.todo.handshake.push(t); } diff --git a/docs/notes.sh b/docs/notes.sh index 627dfaa7..afc8d236 100644 --- a/docs/notes.sh +++ b/docs/notes.sh @@ -31,6 +31,14 @@ mkdir -p "${dirs[@]}" for dir in "${dirs[@]}"; do for fn in ふが "$(printf \\xed\\x93)" 'qwe,rty;asd fgh+jkl%zxc&vbn "rty'"'"'uio&asd fgh'; do echo "$dir" > "$dir/$fn.html"; done; done +## +## upload mojibake + +fn=$(printf '\xba\xdc\xab.cab') +echo asdf > "$fn" +curl --cookie cppwd=wark -sF "act=bput" -F "f=@$fn" http://127.0.0.1:1234/moji/%ED%91/ + + ## ## test compression @@ -61,3 +69,10 @@ ps ax | awk '/python[23]? -m copyparty|python[ ]-c from multiproc/ {print $1}' | # last line of each function in a file cat copyparty/httpcli.py | awk '/^[^a-zA-Z0-9]+def / {printf "%s\n%s\n\n", f, pl; f=$2} /[a-zA-Z0-9]/ {pl=$0}' + + +## +## meta + +# create a folder with symlinks to big files +for d in /usr /var; do find $d -type f -size +30M 2>/dev/null; done | while IFS= read -r x; do ln -s "$x" big/; done