From e413007eb0ab1b409f0f4e9d0b84fe02f4e77405 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 31 Jan 2023 18:13:33 +0000 Subject: [PATCH] hide dotfiles from search results by default --- copyparty/__main__.py | 9 +++++++++ copyparty/authsrv.py | 2 ++ copyparty/httpcli.py | 2 +- copyparty/u2idx.py | 8 ++++++-- tests/util.py | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 7b0306f9..4b2d19d3 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -535,6 +535,8 @@ def get_sects(): \033[36mxlink$\033[35m cross-volume dupe detection / linking \033[36mxdev\033[35m do not descend into other filesystems \033[36mxvol\033[35m skip symlinks leaving the volume root + \033[36mdotsrch\033[35m show dotfiles in search results + \033[36mnodotsrch\033[35m hide dotfiles in search results (default) \033[0mdatabase, audio tags: "mte", "mth", "mtp", "mtm" all work the same as -mte, -mth, ... @@ -552,6 +554,12 @@ def get_sects(): \033[36mhtml_head=TXT\033[35m includes TXT in the \033[36mrobots\033[35m allows indexing by search engines (default) \033[36mnorobots\033[35m kindly asks search engines to leave + \033[36mno_sb_md\033[35m disable js sandbox for markdown files + \033[36mno_sb_lg\033[35m disable js sandbox for prologue/epilogue + \033[36msb_md\033[35m enable js sandbox for markdown files (default) + \033[36msb_lg\033[35m enable js sandbox for prologue/epilogue (default) + \033[36mmd_sbf\033[35m list of markdown-sandbox safeguards to disable + \033[36mlg_sbf\033[35m list of *logue-sandbox safeguards to disable \033[0mothers: \033[36mfk=8\033[35m generates per-file accesskeys, @@ -944,6 +952,7 @@ def add_db_general(ap, hcores): ap2.add_argument("--db-act", metavar="SEC", type=float, default=10, help="defer any scheduled volume reindexing until SEC seconds after last db write (uploads, renames, ...)") ap2.add_argument("--srch-time", metavar="SEC", type=int, default=45, help="search deadline -- terminate searches running for more than SEC seconds") ap2.add_argument("--srch-hits", metavar="N", type=int, default=7999, help="max search results to allow clients to fetch; 125 results will be shown initially") + ap2.add_argument("--dotsrch", action="store_true", help="show dotfiles in search results (volflags: dotsrch | nodotsrch)") def add_db_metadata(ap): diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index f6f9c1b9..789c7af5 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -1128,6 +1128,7 @@ class AuthSrv(object): ("no_dedup", "copydupes"), ("magic", "magic"), ("xlink", "xlink"), + ("dotsrch", "dotsrch"), ): if getattr(self.args, ga): vol.flags[vf] = True @@ -1135,6 +1136,7 @@ class AuthSrv(object): for ve, vd in ( ("sb_md", "no_sb_md"), ("sb_lg", "no_sb_lg"), + ("nodotsrch", "dotsrch"), ): if ve in vol.flags: vol.flags.pop(vd, None) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 254b50a6..9f500378 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -3355,7 +3355,7 @@ class HttpCli(object): if not self.args.no_readme and not logues[1]: for fn in ["README.md", "readme.md"]: fn = os.path.join(abspath, fn) - if bos.path.exists(fn): + if bos.path.isfile(fn): with open(fsenc(fn), "rb") as f: readme = f.read().decode("utf-8") break diff --git a/copyparty/u2idx.py b/copyparty/u2idx.py index a13d4fb2..c886fc47 100644 --- a/copyparty/u2idx.py +++ b/copyparty/u2idx.py @@ -311,6 +311,7 @@ class U2idx(object): sret = [] fk = flags.get("fk") + dots = flags.get("dotsrch") c = cur.execute(uq, tuple(vuv)) for hit in c: w, ts, sz, rd, fn, ip, at = hit[:7] @@ -321,6 +322,10 @@ class U2idx(object): if rd.startswith("//") or fn.startswith("//"): rd, fn = s3dec(rd, fn) + rp = quotep("/".join([x for x in [vtop, rd, fn] if x])) + if not dots and "/." in ("/" + rp): + continue + if not fk: suf = "" else: @@ -337,8 +342,7 @@ class U2idx(object): )[:fk] ) - rp = quotep("/".join([x for x in [vtop, rd, fn] if x])) + suf - sret.append({"ts": int(ts), "sz": sz, "rp": rp, "w": w[:16]}) + sret.append({"ts": int(ts), "sz": sz, "rp": rp + suf, "w": w[:16]}) for hit in sret: w = hit["w"] diff --git a/tests/util.py b/tests/util.py index b0c2c05c..b23fa669 100644 --- a/tests/util.py +++ b/tests/util.py @@ -98,7 +98,7 @@ class Cfg(Namespace): def __init__(self, a=None, v=None, c=None): ka = {} - ex = "daw dav_inf dav_mac e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp ed emp force_js getmod hardlink ihead magic never_symlink nid nih no_acode no_athumb no_dav no_dedup no_del no_dupe no_logues no_mv no_readme no_robots no_sb_md no_sb_lg no_scandir no_thumb no_vthumb no_zip nw xdev xlink xvol" + ex = "daw dav_inf dav_mac dotsrch e2d e2ds e2dsa e2t e2ts e2tsr e2v e2vu e2vp ed emp force_js getmod hardlink ihead magic never_symlink nid nih no_acode no_athumb no_dav no_dedup no_del no_dupe no_logues no_mv no_readme no_robots no_sb_md no_sb_lg no_scandir no_thumb no_vthumb no_zip nw xdev xlink xvol" ka.update(**{k: False for k in ex.split()}) ex = "dotpart no_rescan no_sendfile no_voldump plain_ip"