windows: set .hist folder hidden

This commit is contained in:
ed 2022-12-07 22:56:30 +00:00
parent 7a57c9dbf1
commit 06fa78f54a
4 changed files with 23 additions and 4 deletions

View file

@ -24,13 +24,15 @@ def listdir(p: str = ".") -> list[str]:
return [fsdec(x) for x in os.listdir(fsenc(p))] 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) bname = fsenc(name)
try: try:
os.makedirs(bname, mode) os.makedirs(bname, mode)
return True
except: except:
if not exist_ok or not os.path.isdir(bname): if not exist_ok or not os.path.isdir(bname):
raise raise
return False
def mkdir(p: str, mode: int = 0o755) -> None: def mkdir(p: str, mode: int = 0o755) -> None:

View file

@ -63,6 +63,7 @@ from .util import (
read_socket_unbounded, read_socket_unbounded,
relchk, relchk,
ren_open, ren_open,
hidedir,
s3enc, s3enc,
sanitize_fn, sanitize_fn,
sendfile_kern, sendfile_kern,
@ -2177,7 +2178,9 @@ class HttpCli(object):
mdir, mfile = os.path.split(fp) mdir, mfile = os.path.split(fp)
mfile2 = "{}.{:.3f}.md".format(mfile[:-3], srv_lastmod) mfile2 = "{}.{:.3f}.md".format(mfile[:-3], srv_lastmod)
try: try:
bos.mkdir(os.path.join(mdir, ".hist")) dp = os.path.join(mdir, ".hist")
bos.mkdir(dp)
hidedir(dp)
except: except:
pass pass
bos.rename(fp, os.path.join(mdir, ".hist", mfile2)) bos.rename(fp, os.path.join(mdir, ".hist", mfile2))

View file

@ -38,6 +38,7 @@ from .util import (
db_ex_chk, db_ex_chk,
djoin, djoin,
fsenc, fsenc,
hidedir,
min_ex, min_ex,
quotep, quotep,
ren_open, ren_open,
@ -654,7 +655,8 @@ class Up2k(object):
if not HAVE_SQLITE3 or "e2d" not in flags or "d2d" in flags: if not HAVE_SQLITE3 or "e2d" not in flags or "d2d" in flags:
return None return None
bos.makedirs(histpath) if bos.makedirs(histpath):
hidedir(histpath)
try: try:
cur = self._open_db(db_path) cur = self._open_db(db_path)
@ -3074,7 +3076,8 @@ class Up2k(object):
if etag == self.snap_prev.get(ptop): if etag == self.snap_prev.get(ptop):
return return
bos.makedirs(histpath) if bos.makedirs(histpath):
hidedir(histpath)
path2 = "{}.{}".format(path, os.getpid()) path2 = "{}.{}".format(path, os.getpid())
body = {"droppable": self.droppable[ptop], "registry": reg} body = {"droppable": self.droppable[ptop], "registry": reg}

View file

@ -2562,6 +2562,17 @@ def termsize() -> tuple[int, int]:
return 80, 25 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): class Pebkac(Exception):
def __init__(self, code: int, msg: Optional[str] = None) -> None: def __init__(self, code: int, msg: Optional[str] = None) -> None:
super(Pebkac, self).__init__(msg or HTTPCODE[code]) super(Pebkac, self).__init__(msg or HTTPCODE[code])