mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
disk-info: both free+total on windows too (#272)
This commit is contained in:
parent
7a13728dbb
commit
0476950ac9
|
@ -6157,13 +6157,13 @@ class HttpCli(object):
|
|||
self.log("#wow #whoa")
|
||||
|
||||
if not self.args.nid:
|
||||
free, total, _ = get_df(abspath, False)
|
||||
if total is not None:
|
||||
free, total, zs = get_df(abspath, False)
|
||||
if total:
|
||||
h1 = humansize(free or 0)
|
||||
h2 = humansize(total)
|
||||
srv_info.append("{} free of {}".format(h1, h2))
|
||||
elif free is not None:
|
||||
srv_info.append(humansize(free, True) + " free")
|
||||
elif zs:
|
||||
self.log("diskfree(%r): %s" % (abspath, zs), 3)
|
||||
|
||||
srv_infot = "</span> // <span>".join(srv_info)
|
||||
|
||||
|
|
|
@ -2662,7 +2662,7 @@ def wunlink(log: "NamedLogger", abspath: str, flags: dict[str, Any]) -> bool:
|
|||
return _fs_mvrm(log, abspath, "", False, flags)
|
||||
|
||||
|
||||
def get_df(abspath: str, prune: bool) -> tuple[Optional[int], Optional[int], str]:
|
||||
def get_df(abspath: str, prune: bool) -> tuple[int, int, str]:
|
||||
try:
|
||||
ap = fsenc(abspath)
|
||||
while prune and not os.path.isdir(ap) and BOS_SEP in ap:
|
||||
|
@ -2673,17 +2673,22 @@ def get_df(abspath: str, prune: bool) -> tuple[Optional[int], Optional[int], str
|
|||
assert ctypes # type: ignore # !rm
|
||||
abspath = fsdec(ap)
|
||||
bfree = ctypes.c_ulonglong(0)
|
||||
btotal = ctypes.c_ulonglong(0)
|
||||
bavail = ctypes.c_ulonglong(0)
|
||||
ctypes.windll.kernel32.GetDiskFreeSpaceExW( # type: ignore
|
||||
ctypes.c_wchar_p(abspath), None, None, ctypes.pointer(bfree)
|
||||
ctypes.c_wchar_p(abspath),
|
||||
ctypes.pointer(bavail),
|
||||
ctypes.pointer(btotal),
|
||||
ctypes.pointer(bfree),
|
||||
)
|
||||
return (bfree.value, None, "")
|
||||
return (bavail.value, btotal.value, "")
|
||||
else:
|
||||
sv = os.statvfs(ap)
|
||||
free = sv.f_frsize * sv.f_bfree
|
||||
total = sv.f_frsize * sv.f_blocks
|
||||
return (free, total, "")
|
||||
except Exception as ex:
|
||||
return (None, None, repr(ex))
|
||||
return (0, 0, repr(ex))
|
||||
|
||||
|
||||
if not ANYWIN and not MACOS:
|
||||
|
|
Loading…
Reference in a new issue