mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
fuse.py prefers ?ls if available
This commit is contained in:
parent
2d2e8a3da7
commit
5e3775c1af
|
@ -33,6 +33,7 @@ import re
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
import stat
|
import stat
|
||||||
import errno
|
import errno
|
||||||
import struct
|
import struct
|
||||||
|
@ -323,7 +324,7 @@ class Gateway(object):
|
||||||
if bad_good:
|
if bad_good:
|
||||||
path = dewin(path)
|
path = dewin(path)
|
||||||
|
|
||||||
web_path = self.quotep("/" + "/".join([self.web_root, path])) + "?dots"
|
web_path = self.quotep("/" + "/".join([self.web_root, path])) + "?dots&ls"
|
||||||
r = self.sendreq("GET", web_path)
|
r = self.sendreq("GET", web_path)
|
||||||
if r.status != 200:
|
if r.status != 200:
|
||||||
self.closeconn()
|
self.closeconn()
|
||||||
|
@ -334,12 +335,17 @@ class Gateway(object):
|
||||||
)
|
)
|
||||||
raise FuseOSError(errno.ENOENT)
|
raise FuseOSError(errno.ENOENT)
|
||||||
|
|
||||||
if not r.getheader("Content-Type", "").startswith("text/html"):
|
ctype = r.getheader("Content-Type", "")
|
||||||
|
if ctype == "application/json":
|
||||||
|
parser = self.parse_jls
|
||||||
|
elif ctype.startswith("text/html"):
|
||||||
|
parser = self.parse_html
|
||||||
|
else:
|
||||||
log("listdir on file: {}".format(path))
|
log("listdir on file: {}".format(path))
|
||||||
raise FuseOSError(errno.ENOENT)
|
raise FuseOSError(errno.ENOENT)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return self.parse_html(r)
|
return parser(r)
|
||||||
except:
|
except:
|
||||||
info(repr(path) + "\n" + traceback.format_exc())
|
info(repr(path) + "\n" + traceback.format_exc())
|
||||||
raise
|
raise
|
||||||
|
@ -367,6 +373,29 @@ class Gateway(object):
|
||||||
|
|
||||||
return r.read()
|
return r.read()
|
||||||
|
|
||||||
|
def parse_jls(self, datasrc):
|
||||||
|
rsp = b""
|
||||||
|
while True:
|
||||||
|
buf = datasrc.read(1024 * 32)
|
||||||
|
if not buf:
|
||||||
|
break
|
||||||
|
|
||||||
|
rsp += buf
|
||||||
|
|
||||||
|
rsp = json.loads(rsp.decode("utf-8"))
|
||||||
|
ret = []
|
||||||
|
for is_dir, nodes in [[True, rsp["dirs"]], [False, rsp["files"]]]:
|
||||||
|
for n in nodes:
|
||||||
|
fname = unquote(n["href"]).rstrip(b"/")
|
||||||
|
fname = fname.decode("wtf-8")
|
||||||
|
if bad_good:
|
||||||
|
fname = enwin(fname)
|
||||||
|
|
||||||
|
fun = self.stat_dir if is_dir else self.stat_file
|
||||||
|
ret.append([fname, fun(n["ts"], n["sz"]), 0])
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
def parse_html(self, datasrc):
|
def parse_html(self, datasrc):
|
||||||
ret = []
|
ret = []
|
||||||
remainder = b""
|
remainder = b""
|
||||||
|
@ -818,7 +847,7 @@ class CPPF(Operations):
|
||||||
return cache_stat
|
return cache_stat
|
||||||
|
|
||||||
fun = info
|
fun = info
|
||||||
if MACOS and path.split('/')[-1].startswith('._'):
|
if MACOS and path.split("/")[-1].startswith("._"):
|
||||||
fun = dbg
|
fun = dbg
|
||||||
|
|
||||||
fun("=ENOENT ({})".format(hexler(path)))
|
fun("=ENOENT ({})".format(hexler(path)))
|
||||||
|
|
|
@ -1084,7 +1084,7 @@ class HttpCli(object):
|
||||||
|
|
||||||
ret = self.gen_tree(top, dst)
|
ret = self.gen_tree(top, dst)
|
||||||
ret = json.dumps(ret)
|
ret = json.dumps(ret)
|
||||||
self.reply(ret.encode("utf-8"))
|
self.reply(ret.encode("utf-8"), mime="application/json")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def gen_tree(self, top, target):
|
def gen_tree(self, top, target):
|
||||||
|
@ -1270,7 +1270,7 @@ class HttpCli(object):
|
||||||
if is_ls:
|
if is_ls:
|
||||||
[x.pop("name") for y in [dirs, files] for x in y]
|
[x.pop("name") for y in [dirs, files] for x in y]
|
||||||
ret = json.dumps({"dirs": dirs, "files": files, "srvinf": srv_info})
|
ret = json.dumps({"dirs": dirs, "files": files, "srvinf": srv_info})
|
||||||
self.reply(ret.encode("utf-8", "replace"))
|
self.reply(ret.encode("utf-8", "replace"), mime="application/json")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
logues = [None, None]
|
logues = [None, None]
|
||||||
|
|
Loading…
Reference in a new issue