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))]
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:

View file

@ -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))

View file

@ -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}

View file

@ -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])