From 06fa78f54a99ec07472d99bbd2a48739a73bed36 Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 7 Dec 2022 22:56:30 +0000 Subject: [PATCH] windows: set .hist folder hidden --- copyparty/bos/bos.py | 4 +++- copyparty/httpcli.py | 5 ++++- copyparty/up2k.py | 7 +++++-- copyparty/util.py | 11 +++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/copyparty/bos/bos.py b/copyparty/bos/bos.py index 125dc111..a1981d31 100644 --- a/copyparty/bos/bos.py +++ b/copyparty/bos/bos.py @@ -24,13 +24,15 @@ def listdir(p: str = ".") -> list[str]: return [fsdec(x) for x in os.listdir(fsenc(p))] -def makedirs(name: str, mode: int = 0o755, exist_ok: bool = True) -> None: +def makedirs(name: str, mode: int = 0o755, exist_ok: bool = True) -> bool: bname = fsenc(name) try: os.makedirs(bname, mode) + return True except: if not exist_ok or not os.path.isdir(bname): raise + return False def mkdir(p: str, mode: int = 0o755) -> None: diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index cde9cff2..5f392f87 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -63,6 +63,7 @@ from .util import ( read_socket_unbounded, relchk, ren_open, + hidedir, s3enc, sanitize_fn, sendfile_kern, @@ -2177,7 +2178,9 @@ class HttpCli(object): mdir, mfile = os.path.split(fp) mfile2 = "{}.{:.3f}.md".format(mfile[:-3], srv_lastmod) try: - bos.mkdir(os.path.join(mdir, ".hist")) + dp = os.path.join(mdir, ".hist") + bos.mkdir(dp) + hidedir(dp) except: pass bos.rename(fp, os.path.join(mdir, ".hist", mfile2)) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 1dc03b0e..868db520 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -38,6 +38,7 @@ from .util import ( db_ex_chk, djoin, fsenc, + hidedir, min_ex, quotep, ren_open, @@ -654,7 +655,8 @@ class Up2k(object): if not HAVE_SQLITE3 or "e2d" not in flags or "d2d" in flags: return None - bos.makedirs(histpath) + if bos.makedirs(histpath): + hidedir(histpath) try: cur = self._open_db(db_path) @@ -3074,7 +3076,8 @@ class Up2k(object): if etag == self.snap_prev.get(ptop): return - bos.makedirs(histpath) + if bos.makedirs(histpath): + hidedir(histpath) path2 = "{}.{}".format(path, os.getpid()) body = {"droppable": self.droppable[ptop], "registry": reg} diff --git a/copyparty/util.py b/copyparty/util.py index f3b9f33b..ee8c79eb 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -2562,6 +2562,17 @@ def termsize() -> tuple[int, int]: return 80, 25 +def hidedir(dp) -> None: + if ANYWIN: + try: + k32 = ctypes.WinDLL("kernel32") + attrs = k32.GetFileAttributesW(dp) + if attrs >= 0: + k32.SetFileAttributesW(dp, attrs | 2) + except: + pass + + class Pebkac(Exception): def __init__(self, code: int, msg: Optional[str] = None) -> None: super(Pebkac, self).__init__(msg or HTTPCODE[code])