Skip to content

Commit 5c6341e

Browse files
committed
disk-info: both free+total on windows too (#272)
1 parent fbf17be commit 5c6341e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

copyparty/httpcli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6157,13 +6157,13 @@ def tx_browser(self) -> bool:
61576157
self.log("#wow #whoa")
61586158

61596159
if not self.args.nid:
6160-
free, total, _ = get_df(abspath, False)
6161-
if total is not None:
6160+
free, total, zs = get_df(abspath, False)
6161+
if total:
61626162
h1 = humansize(free or 0)
61636163
h2 = humansize(total)
61646164
srv_info.append("{} free of {}".format(h1, h2))
6165-
elif free is not None:
6166-
srv_info.append(humansize(free, True) + " free")
6165+
elif zs:
6166+
self.log("diskfree(%r): %s" % (abspath, zs), 3)
61676167

61686168
srv_infot = "</span> // <span>".join(srv_info)
61696169

copyparty/util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,7 +2662,7 @@ def wunlink(log: "NamedLogger", abspath: str, flags: dict[str, Any]) -> bool:
26622662
return _fs_mvrm(log, abspath, "", False, flags)
26632663

26642664

2665-
def get_df(abspath: str, prune: bool) -> tuple[Optional[int], Optional[int], str]:
2665+
def get_df(abspath: str, prune: bool) -> tuple[int, int, str]:
26662666
try:
26672667
ap = fsenc(abspath)
26682668
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
26732673
assert ctypes # type: ignore # !rm
26742674
abspath = fsdec(ap)
26752675
bfree = ctypes.c_ulonglong(0)
2676+
btotal = ctypes.c_ulonglong(0)
2677+
bavail = ctypes.c_ulonglong(0)
26762678
ctypes.windll.kernel32.GetDiskFreeSpaceExW( # type: ignore
2677-
ctypes.c_wchar_p(abspath), None, None, ctypes.pointer(bfree)
2679+
ctypes.c_wchar_p(abspath),
2680+
ctypes.pointer(bavail),
2681+
ctypes.pointer(btotal),
2682+
ctypes.pointer(bfree),
26782683
)
2679-
return (bfree.value, None, "")
2684+
return (bavail.value, btotal.value, "")
26802685
else:
26812686
sv = os.statvfs(ap)
26822687
free = sv.f_frsize * sv.f_bfree
26832688
total = sv.f_frsize * sv.f_blocks
26842689
return (free, total, "")
26852690
except Exception as ex:
2686-
return (None, None, repr(ex))
2691+
return (0, 0, repr(ex))
26872692

26882693

26892694
if not ANYWIN and not MACOS:

0 commit comments

Comments
 (0)