mirror of
https://github.com/9001/copyparty.git
synced 2026-06-18 20:22:27 -06:00
tail: use counted offsets (closes #1449);
avoids spurious reopen on some fs
This commit is contained in:
parent
37e68f60a6
commit
8173018926
|
|
@ -4897,15 +4897,8 @@ class HttpCli(object):
|
||||||
dl_id,
|
dl_id,
|
||||||
)
|
)
|
||||||
sent = (eof - ofs) - remains
|
sent = (eof - ofs) - remains
|
||||||
ofs = eof - remains
|
f.seek(eof - remains)
|
||||||
f.seek(ofs)
|
ofs = f.tell()
|
||||||
|
|
||||||
try:
|
|
||||||
st2 = os.stat(open_args[0])
|
|
||||||
if st.st_ino == st2.st_ino:
|
|
||||||
st = st2 # for filesize
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
gone = 0
|
gone = 0
|
||||||
unsent = False
|
unsent = False
|
||||||
|
|
@ -4925,6 +4918,7 @@ class HttpCli(object):
|
||||||
t_fd = t_ka = now
|
t_fd = t_ka = now
|
||||||
self.s.sendall(buf)
|
self.s.sendall(buf)
|
||||||
sent += len(buf)
|
sent += len(buf)
|
||||||
|
ofs += len(buf)
|
||||||
unsent = False
|
unsent = False
|
||||||
dls[dl_id] = (time.time(), sent)
|
dls[dl_id] = (time.time(), sent)
|
||||||
continue
|
continue
|
||||||
|
|
@ -4935,14 +4929,9 @@ class HttpCli(object):
|
||||||
self.s.send(b"\x00")
|
self.s.send(b"\x00")
|
||||||
if t_fd < now - sec_fd:
|
if t_fd < now - sec_fd:
|
||||||
try:
|
try:
|
||||||
st2 = os.stat(open_args[0])
|
st2 = os.stat(abspath)
|
||||||
szd = st2.st_size - st.st_size
|
szd = st2.st_size - ofs
|
||||||
if (
|
if st2.st_ino != st.st_ino or szd < 0 or unsent:
|
||||||
st2.st_ino != st.st_ino
|
|
||||||
or st2.st_size < sent
|
|
||||||
or szd < 0
|
|
||||||
or unsent
|
|
||||||
):
|
|
||||||
assert f # !rm
|
assert f # !rm
|
||||||
# open new file before closing previous to avoid toctous (open may fail; cannot null f before)
|
# open new file before closing previous to avoid toctous (open may fail; cannot null f before)
|
||||||
f2 = open_nolock(*open_args)
|
f2 = open_nolock(*open_args)
|
||||||
|
|
@ -4950,15 +4939,15 @@ class HttpCli(object):
|
||||||
f = f2
|
f = f2
|
||||||
f.seek(0, os.SEEK_END)
|
f.seek(0, os.SEEK_END)
|
||||||
eof = f.tell()
|
eof = f.tell()
|
||||||
if eof < sent:
|
if eof < ofs:
|
||||||
ofs = sent = 0 # shrunk; send from start
|
ofs = 0 # shrunk; send from start
|
||||||
zb = b"\n\n*** file size decreased -- rewinding to the start of the file ***\n\n"
|
zb = b"\n\n*** file size decreased -- rewinding to the start of the file ***\n\n"
|
||||||
self.s.sendall(zb)
|
self.s.sendall(zb)
|
||||||
if ofs0 < 0 and eof > -ofs0:
|
if ofs0 < 0 and eof > -ofs0:
|
||||||
ofs = eof + ofs0
|
ofs = eof + ofs0
|
||||||
else:
|
# else: probably just new fd; resume from same ofs
|
||||||
ofs = sent # just new fd? resume from same ofs
|
|
||||||
f.seek(ofs)
|
f.seek(ofs)
|
||||||
|
ofs = f.tell()
|
||||||
self.log("reopened at byte %d: %r" % (ofs, abspath), 6)
|
self.log("reopened at byte %d: %r" % (ofs, abspath), 6)
|
||||||
unsent = False
|
unsent = False
|
||||||
gone = 0
|
gone = 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue