mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 01:22:13 -06:00
add .PARTIAL suffix to bup uploads too +
aggressive limits checking
This commit is contained in:
parent
903b9e627a
commit
ad7413a5ff
|
@ -43,6 +43,7 @@ from .util import (
|
||||||
Pebkac,
|
Pebkac,
|
||||||
UnrecvEOF,
|
UnrecvEOF,
|
||||||
alltrace,
|
alltrace,
|
||||||
|
atomic_move,
|
||||||
exclude_dotfiles,
|
exclude_dotfiles,
|
||||||
fsenc,
|
fsenc,
|
||||||
gen_filekey,
|
gen_filekey,
|
||||||
|
@ -1257,9 +1258,19 @@ class HttpCli(object):
|
||||||
|
|
||||||
suffix = "-{:.6f}-{}".format(time.time(), self.dip)
|
suffix = "-{:.6f}-{}".format(time.time(), self.dip)
|
||||||
open_args = {"fdir": fdir, "suffix": suffix}
|
open_args = {"fdir": fdir, "suffix": suffix}
|
||||||
|
|
||||||
|
# reserve destination filename
|
||||||
|
with ren_open(fname, "wb", fdir=fdir, suffix=suffix) as zfw:
|
||||||
|
fname = zfw["orz"][1]
|
||||||
|
|
||||||
|
tnam = fname + ".PARTIAL"
|
||||||
|
if self.args.dotpart:
|
||||||
|
tnam = "." + tnam
|
||||||
|
|
||||||
|
abspath = os.path.join(fdir, fname)
|
||||||
else:
|
else:
|
||||||
open_args = {}
|
open_args = {}
|
||||||
fname = os.devnull
|
tnam = fname = os.devnull
|
||||||
fdir = ""
|
fdir = ""
|
||||||
|
|
||||||
if lim:
|
if lim:
|
||||||
|
@ -1267,11 +1278,14 @@ class HttpCli(object):
|
||||||
lim.chk_nup(self.ip)
|
lim.chk_nup(self.ip)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with ren_open(fname, "wb", 512 * 1024, **open_args) as zfw:
|
max_sz = lim.smax if lim else 0
|
||||||
f, fname = zfw["orz"]
|
with ren_open(tnam, "wb", 512 * 1024, **open_args) as zfw:
|
||||||
abspath = os.path.join(fdir, fname)
|
f, tnam = zfw["orz"]
|
||||||
self.log("writing to {}".format(abspath))
|
tabspath = os.path.join(fdir, tnam)
|
||||||
sz, sha_hex, sha_b64 = hashcopy(p_data, f, self.args.s_wr_slp)
|
self.log("writing to {}".format(tabspath))
|
||||||
|
sz, sha_hex, sha_b64 = hashcopy(
|
||||||
|
p_data, f, self.args.s_wr_slp, max_sz
|
||||||
|
)
|
||||||
if sz == 0:
|
if sz == 0:
|
||||||
raise Pebkac(400, "empty files in post")
|
raise Pebkac(400, "empty files in post")
|
||||||
|
|
||||||
|
@ -1280,11 +1294,15 @@ class HttpCli(object):
|
||||||
lim.bup(self.ip, sz)
|
lim.bup(self.ip, sz)
|
||||||
try:
|
try:
|
||||||
lim.chk_sz(sz)
|
lim.chk_sz(sz)
|
||||||
|
lim.chk_bup(self.ip)
|
||||||
|
lim.chk_nup(self.ip)
|
||||||
except:
|
except:
|
||||||
|
bos.unlink(tabspath)
|
||||||
bos.unlink(abspath)
|
bos.unlink(abspath)
|
||||||
fname = os.devnull
|
fname = os.devnull
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
atomic_move(tabspath, abspath)
|
||||||
files.append(
|
files.append(
|
||||||
(sz, sha_hex, sha_b64, p_file or "(discarded)", fname, abspath)
|
(sz, sha_hex, sha_b64, p_file or "(discarded)", fname, abspath)
|
||||||
)
|
)
|
||||||
|
@ -1301,19 +1319,7 @@ class HttpCli(object):
|
||||||
self.conn.nbyte += sz
|
self.conn.nbyte += sz
|
||||||
|
|
||||||
except Pebkac:
|
except Pebkac:
|
||||||
if fname != os.devnull:
|
self.parser.drop()
|
||||||
fp = os.path.join(fdir, fname)
|
|
||||||
fp2 = fp
|
|
||||||
if self.args.dotpart:
|
|
||||||
fp2 = os.path.join(fdir, "." + fname)
|
|
||||||
|
|
||||||
suffix = ".PARTIAL"
|
|
||||||
try:
|
|
||||||
bos.rename(fp, fp2 + suffix)
|
|
||||||
except:
|
|
||||||
fp2 = fp2[: -len(suffix) - 1]
|
|
||||||
bos.rename(fp, fp2 + suffix)
|
|
||||||
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
except Pebkac as ex:
|
except Pebkac as ex:
|
||||||
|
|
|
@ -1270,11 +1270,15 @@ def hashcopy(
|
||||||
fin: Union[typing.BinaryIO, Generator[bytes, None, None]],
|
fin: Union[typing.BinaryIO, Generator[bytes, None, None]],
|
||||||
fout: Union[typing.BinaryIO, typing.IO[Any]],
|
fout: Union[typing.BinaryIO, typing.IO[Any]],
|
||||||
slp: int = 0,
|
slp: int = 0,
|
||||||
|
max_sz: int = 0,
|
||||||
) -> tuple[int, str, str]:
|
) -> tuple[int, str, str]:
|
||||||
hashobj = hashlib.sha512()
|
hashobj = hashlib.sha512()
|
||||||
tlen = 0
|
tlen = 0
|
||||||
for buf in fin:
|
for buf in fin:
|
||||||
tlen += len(buf)
|
tlen += len(buf)
|
||||||
|
if max_sz and tlen > max_sz:
|
||||||
|
continue
|
||||||
|
|
||||||
hashobj.update(buf)
|
hashobj.update(buf)
|
||||||
fout.write(buf)
|
fout.write(buf)
|
||||||
if slp:
|
if slp:
|
||||||
|
|
Loading…
Reference in a new issue