ensure file can be opened before replying 200 and...

* make gen_tree 0.1% faster
* improve filekey warning message
* fix oversight in 0c50ea1757
* support `--xdev` on windows (the python docs mention that os.scandir
   doesn't assign st_ino, st_dev and st_nlink on win but i can't read)
This commit is contained in:
ed 2023-12-20 01:07:45 +00:00
parent 0c50ea1757
commit ac7815a0ae
2 changed files with 15 additions and 12 deletions

View file

@ -498,7 +498,7 @@ class HttpCli(object):
self.can_admin, self.can_admin,
self.can_dot, self.can_dot,
) = ( ) = (
avn.can_access("", self.uname) if avn else [False] * 7 avn.can_access("", self.uname) if avn else [False] * 8
) )
self.avn = avn self.avn = avn
self.vn = vn self.vn = vn
@ -2960,18 +2960,19 @@ class HttpCli(object):
mime = "text/plain; charset=utf-8" mime = "text/plain; charset=utf-8"
self.out_headers["Accept-Ranges"] = "bytes" self.out_headers["Accept-Ranges"] = "bytes"
self.send_headers(length=upper - lower, status=status, mime=mime)
logmsg += unicode(status) + logtail logmsg += unicode(status) + logtail
if self.mode == "HEAD" or not do_send: if self.mode == "HEAD" or not do_send:
if self.do_log: if self.do_log:
self.log(logmsg) self.log(logmsg)
self.send_headers(length=upper - lower, status=status, mime=mime)
return True return True
ret = True ret = True
with open_func(*open_args) as f: with open_func(*open_args) as f:
self.send_headers(length=upper - lower, status=status, mime=mime)
sendfun = sendfile_kern if use_sendfile else sendfile_py sendfun = sendfile_kern if use_sendfile else sendfile_py
remains = sendfun( remains = sendfun(
self.log, lower, upper, f, self.s, self.args.s_wr_sz, self.args.s_wr_slp self.log, lower, upper, f, self.s, self.args.s_wr_sz, self.args.s_wr_slp
@ -2979,7 +2980,7 @@ class HttpCli(object):
if remains > 0: if remains > 0:
logmsg += " \033[31m" + unicode(upper - remains) + "\033[0m" logmsg += " \033[31m" + unicode(upper - remains) + "\033[0m"
self.keepalive = False ret = False
spd = self._spd((upper - lower) - remains) spd = self._spd((upper - lower) - remains)
if self.do_log: if self.do_log:
@ -3483,15 +3484,12 @@ class HttpCli(object):
if d1 == top: if d1 == top:
vfs_virt[d2] = vfs # typechk, value never read vfs_virt[d2] = vfs # typechk, value never read
dirs = [] dirs = [x[0] for x in vfs_ls if stat.S_ISDIR(x[1].st_mode)]
dirnames = [x[0] for x in vfs_ls if stat.S_ISDIR(x[1].st_mode)]
if not dots or "dots" not in self.uparam: if not dots or "dots" not in self.uparam:
dirnames = exclude_dotfiles(dirnames) dirs = exclude_dotfiles(dirs)
for fn in [x for x in dirnames if x != excl]: dirs = [quotep(x) for x in dirs if x != excl]
dirs.append(quotep(fn))
for x in vfs_virt: for x in vfs_virt:
if x != excl: if x != excl:
@ -3835,7 +3833,8 @@ class HttpCli(object):
)[: vn.flags["fk"]] )[: vn.flags["fk"]]
got = self.uparam.get("k") got = self.uparam.get("k")
if got != correct: if got != correct:
self.log("wrong filekey, want {}, got {}".format(correct, got)) t = "wrong filekey, want %s, got %s\n vp: %s\n ap: %s"
self.log(t % (correct, got, self.req, abspath), 6)
return self.tx_404() return self.tx_404()
if ( if (

View file

@ -1118,7 +1118,11 @@ class Up2k(object):
if stat.S_ISDIR(inf.st_mode): if stat.S_ISDIR(inf.st_mode):
rap = absreal(abspath) rap = absreal(abspath)
if dev and inf.st_dev != dev: if (
dev
and inf.st_dev != dev
and not (ANYWIN and bos.stat(rap).st_dev == dev)
):
self.log("skip xdev {}->{}: {}".format(dev, inf.st_dev, abspath), 6) self.log("skip xdev {}->{}: {}".format(dev, inf.st_dev, abspath), 6)
continue continue
if abspath in excl or rap in excl: if abspath in excl or rap in excl: