mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
mojibake fixes
This commit is contained in:
parent
38d8d9733f
commit
d25881d5c3
|
@ -428,7 +428,7 @@ class HttpCli(object):
|
||||||
fn = "put-{:.6f}-{}.bin".format(time.time(), addr)
|
fn = "put-{:.6f}-{}.bin".format(time.time(), addr)
|
||||||
path = os.path.join(fdir, fn)
|
path = os.path.join(fdir, fn)
|
||||||
|
|
||||||
with open(path, "wb", 512 * 1024) as f:
|
with open(fsenc(path), "wb", 512 * 1024) as f:
|
||||||
post_sz, _, sha_b64 = hashcopy(self.conn, reader, f)
|
post_sz, _, sha_b64 = hashcopy(self.conn, reader, f)
|
||||||
|
|
||||||
self.conn.hsrv.broker.put(
|
self.conn.hsrv.broker.put(
|
||||||
|
@ -548,9 +548,9 @@ class HttpCli(object):
|
||||||
if sub:
|
if sub:
|
||||||
try:
|
try:
|
||||||
dst = os.path.join(vfs.realpath, rem)
|
dst = os.path.join(vfs.realpath, rem)
|
||||||
os.makedirs(dst)
|
os.makedirs(fsenc(dst))
|
||||||
except:
|
except:
|
||||||
if not os.path.isdir(dst):
|
if not os.path.isdir(fsenc(dst)):
|
||||||
raise Pebkac(400, "some file got your folder name")
|
raise Pebkac(400, "some file got your folder name")
|
||||||
|
|
||||||
x = self.conn.hsrv.broker.put(True, "up2k.handle_json", body)
|
x = self.conn.hsrv.broker.put(True, "up2k.handle_json", body)
|
||||||
|
@ -638,7 +638,7 @@ class HttpCli(object):
|
||||||
|
|
||||||
reader = read_socket(self.sr, remains)
|
reader = read_socket(self.sr, remains)
|
||||||
|
|
||||||
with open(path, "rb+", 512 * 1024) as f:
|
with open(fsenc(path), "rb+", 512 * 1024) as f:
|
||||||
f.seek(cstart[0])
|
f.seek(cstart[0])
|
||||||
post_sz, _, sha_b64 = hashcopy(self.conn, reader, f)
|
post_sz, _, sha_b64 = hashcopy(self.conn, reader, f)
|
||||||
|
|
||||||
|
@ -681,7 +681,7 @@ class HttpCli(object):
|
||||||
times = (int(time.time()), int(lastmod))
|
times = (int(time.time()), int(lastmod))
|
||||||
self.log("no more chunks, setting times {}".format(times))
|
self.log("no more chunks, setting times {}".format(times))
|
||||||
try:
|
try:
|
||||||
os.utime(path, times)
|
os.utime(fsenc(path), times)
|
||||||
except:
|
except:
|
||||||
self.log("failed to utime ({}, {})".format(path, times))
|
self.log("failed to utime ({}, {})".format(path, times))
|
||||||
|
|
||||||
|
@ -932,16 +932,16 @@ class HttpCli(object):
|
||||||
mdir, mfile = os.path.split(fp)
|
mdir, mfile = os.path.split(fp)
|
||||||
mfile2 = "{}.{:.3f}.md".format(mfile[:-3], srv_lastmod)
|
mfile2 = "{}.{:.3f}.md".format(mfile[:-3], srv_lastmod)
|
||||||
try:
|
try:
|
||||||
os.mkdir(os.path.join(mdir, ".hist"))
|
os.mkdir(fsenc(os.path.join(mdir, ".hist")))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
os.rename(fp, os.path.join(mdir, ".hist", mfile2))
|
os.rename(fsenc(fp), fsenc(os.path.join(mdir, ".hist", mfile2)))
|
||||||
|
|
||||||
p_field, _, p_data = next(self.parser.gen)
|
p_field, _, p_data = next(self.parser.gen)
|
||||||
if p_field != "body":
|
if p_field != "body":
|
||||||
raise Pebkac(400, "expected body, got {}".format(p_field))
|
raise Pebkac(400, "expected body, got {}".format(p_field))
|
||||||
|
|
||||||
with open(fp, "wb", 512 * 1024) as f:
|
with open(fsenc(fp), "wb", 512 * 1024) as f:
|
||||||
sz, sha512, _ = hashcopy(self.conn, p_data, f)
|
sz, sha512, _ = hashcopy(self.conn, p_data, f)
|
||||||
|
|
||||||
new_lastmod = os.stat(fsenc(fp)).st_mtime
|
new_lastmod = os.stat(fsenc(fp)).st_mtime
|
||||||
|
@ -1269,7 +1269,7 @@ class HttpCli(object):
|
||||||
"md_chk_rate": self.args.mcr,
|
"md_chk_rate": self.args.mcr,
|
||||||
"md": boundary,
|
"md": boundary,
|
||||||
}
|
}
|
||||||
html = template.render(**targs).encode("utf-8")
|
html = template.render(**targs).encode("utf-8", "replace")
|
||||||
html = html.split(boundary.encode("utf-8"))
|
html = html.split(boundary.encode("utf-8"))
|
||||||
if len(html) != 2:
|
if len(html) != 2:
|
||||||
raise Exception("boundary appears in " + html_path)
|
raise Exception("boundary appears in " + html_path)
|
||||||
|
@ -1422,7 +1422,7 @@ class HttpCli(object):
|
||||||
)
|
)
|
||||||
srv_info.append(humansize(bfree.value) + " free")
|
srv_info.append(humansize(bfree.value) + " free")
|
||||||
else:
|
else:
|
||||||
sv = os.statvfs(abspath)
|
sv = os.statvfs(fsenc(abspath))
|
||||||
free = humansize(sv.f_frsize * sv.f_bfree, True)
|
free = humansize(sv.f_frsize * sv.f_bfree, True)
|
||||||
total = humansize(sv.f_frsize * sv.f_blocks, True)
|
total = humansize(sv.f_frsize * sv.f_blocks, True)
|
||||||
|
|
||||||
|
|
|
@ -392,7 +392,7 @@ class MTag(object):
|
||||||
import mutagen
|
import mutagen
|
||||||
|
|
||||||
try:
|
try:
|
||||||
md = mutagen.File(abspath, easy=True)
|
md = mutagen.File(fsenc(abspath), easy=True)
|
||||||
x = md.info.length
|
x = md.info.length
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
return {}
|
return {}
|
||||||
|
@ -403,7 +403,7 @@ class MTag(object):
|
||||||
try:
|
try:
|
||||||
q = int(md.info.bitrate / 1024)
|
q = int(md.info.bitrate / 1024)
|
||||||
except:
|
except:
|
||||||
q = int((os.path.getsize(abspath) / dur) / 128)
|
q = int((os.path.getsize(fsenc(abspath)) / dur) / 128)
|
||||||
|
|
||||||
ret[".dur"] = [0, dur]
|
ret[".dur"] = [0, dur]
|
||||||
ret[".q"] = [0, q]
|
ret[".q"] = [0, q]
|
||||||
|
|
|
@ -228,7 +228,7 @@ class ThumbSrv(object):
|
||||||
self.nthr -= 1
|
self.nthr -= 1
|
||||||
|
|
||||||
def conv_pil(self, abspath, tpath):
|
def conv_pil(self, abspath, tpath):
|
||||||
with Image.open(abspath) as im:
|
with Image.open(fsenc(abspath)) as im:
|
||||||
crop = not self.args.th_no_crop
|
crop = not self.args.th_no_crop
|
||||||
res2 = self.res
|
res2 = self.res
|
||||||
if crop:
|
if crop:
|
||||||
|
|
|
@ -163,7 +163,7 @@ class U2idx(object):
|
||||||
if rd.startswith("//") or fn.startswith("//"):
|
if rd.startswith("//") or fn.startswith("//"):
|
||||||
rd, fn = s3dec(rd, fn)
|
rd, fn = s3dec(rd, fn)
|
||||||
|
|
||||||
rp = os.path.join(vtop, rd, fn).replace("\\", "/")
|
rp = "/".join([vtop, rd, fn])
|
||||||
sret.append({"ts": int(ts), "sz": sz, "rp": rp, "w": w[:16]})
|
sret.append({"ts": int(ts), "sz": sz, "rp": rp, "w": w[:16]})
|
||||||
|
|
||||||
for hit in sret:
|
for hit in sret:
|
||||||
|
|
|
@ -918,7 +918,7 @@ class Up2k(object):
|
||||||
if dp_dir.startswith("//") or dp_fn.startswith("//"):
|
if dp_dir.startswith("//") or dp_fn.startswith("//"):
|
||||||
dp_dir, dp_fn = s3dec(dp_dir, dp_fn)
|
dp_dir, dp_fn = s3dec(dp_dir, dp_fn)
|
||||||
|
|
||||||
dp_abs = os.path.join(cj["ptop"], dp_dir, dp_fn).replace("\\", "/")
|
dp_abs = "/".join([cj["ptop"], dp_dir, dp_fn])
|
||||||
# relying on path.exists to return false on broken symlinks
|
# relying on path.exists to return false on broken symlinks
|
||||||
if os.path.exists(fsenc(dp_abs)):
|
if os.path.exists(fsenc(dp_abs)):
|
||||||
job = {
|
job = {
|
||||||
|
@ -944,7 +944,7 @@ class Up2k(object):
|
||||||
for fn in names:
|
for fn in names:
|
||||||
path = os.path.join(job["ptop"], job["prel"], fn)
|
path = os.path.join(job["ptop"], job["prel"], fn)
|
||||||
try:
|
try:
|
||||||
if os.path.getsize(path) > 0:
|
if os.path.getsize(fsenc(path)) > 0:
|
||||||
# upload completed or both present
|
# upload completed or both present
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
|
@ -1068,6 +1068,9 @@ class Up2k(object):
|
||||||
raise Pebkac(400, "unknown wark")
|
raise Pebkac(400, "unknown wark")
|
||||||
|
|
||||||
if chash not in job["need"]:
|
if chash not in job["need"]:
|
||||||
|
msg = "chash = {} , need:\n".format(chash)
|
||||||
|
msg += "\n".join(job["need"])
|
||||||
|
self.log(msg)
|
||||||
raise Pebkac(400, "already got that but thanks??")
|
raise Pebkac(400, "already got that but thanks??")
|
||||||
|
|
||||||
nchunk = [n for n, v in enumerate(job["hash"]) if v == chash]
|
nchunk = [n for n, v in enumerate(job["hash"]) if v == chash]
|
||||||
|
@ -1173,10 +1176,10 @@ class Up2k(object):
|
||||||
return wark
|
return wark
|
||||||
|
|
||||||
def _hashlist_from_file(self, path):
|
def _hashlist_from_file(self, path):
|
||||||
fsz = os.path.getsize(path)
|
fsz = os.path.getsize(fsenc(path))
|
||||||
csz = up2k_chunksize(fsz)
|
csz = up2k_chunksize(fsz)
|
||||||
ret = []
|
ret = []
|
||||||
with open(path, "rb", 512 * 1024) as f:
|
with open(fsenc(path), "rb", 512 * 1024) as f:
|
||||||
while fsz > 0:
|
while fsz > 0:
|
||||||
self.pp.msg = "{} MB, {}".format(int(fsz / 1024 / 1024), path)
|
self.pp.msg = "{} MB, {}".format(int(fsz / 1024 / 1024), path)
|
||||||
hashobj = hashlib.sha512()
|
hashobj = hashlib.sha512()
|
||||||
|
@ -1267,13 +1270,13 @@ class Up2k(object):
|
||||||
try:
|
try:
|
||||||
# remove the filename reservation
|
# remove the filename reservation
|
||||||
path = os.path.join(job["ptop"], job["prel"], job["name"])
|
path = os.path.join(job["ptop"], job["prel"], job["name"])
|
||||||
if os.path.getsize(path) == 0:
|
if os.path.getsize(fsenc(path)) == 0:
|
||||||
os.unlink(path)
|
os.unlink(fsenc(path))
|
||||||
|
|
||||||
if len(job["hash"]) == len(job["need"]):
|
if len(job["hash"]) == len(job["need"]):
|
||||||
# PARTIAL is empty, delete that too
|
# PARTIAL is empty, delete that too
|
||||||
path = os.path.join(job["ptop"], job["prel"], job["tnam"])
|
path = os.path.join(job["ptop"], job["prel"], job["tnam"])
|
||||||
os.unlink(path)
|
os.unlink(fsenc(path))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -1281,8 +1284,8 @@ class Up2k(object):
|
||||||
if not reg:
|
if not reg:
|
||||||
if k not in prev or prev[k] is not None:
|
if k not in prev or prev[k] is not None:
|
||||||
prev[k] = None
|
prev[k] = None
|
||||||
if os.path.exists(path):
|
if os.path.exists(fsenc(path)):
|
||||||
os.unlink(path)
|
os.unlink(fsenc(path))
|
||||||
return
|
return
|
||||||
|
|
||||||
newest = max(x["poke"] for _, x in reg.items()) if reg else 0
|
newest = max(x["poke"] for _, x in reg.items()) if reg else 0
|
||||||
|
|
|
@ -271,7 +271,7 @@ def ren_open(fname, *args, **kwargs):
|
||||||
else:
|
else:
|
||||||
fpath = fname
|
fpath = fname
|
||||||
|
|
||||||
if suffix and os.path.exists(fpath):
|
if suffix and os.path.exists(fsenc(fpath)):
|
||||||
fpath += suffix
|
fpath += suffix
|
||||||
fname += suffix
|
fname += suffix
|
||||||
ext += suffix
|
ext += suffix
|
||||||
|
@ -751,6 +751,8 @@ def s3dec(rd, fn):
|
||||||
|
|
||||||
|
|
||||||
def atomic_move(src, dst):
|
def atomic_move(src, dst):
|
||||||
|
src = fsenc(src)
|
||||||
|
dst = fsenc(dst)
|
||||||
if not PY2:
|
if not PY2:
|
||||||
os.replace(src, dst)
|
os.replace(src, dst)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue