Skip to content

Commit 112e0a7

Browse files
committed
sys.filesystem_type faster
1 parent 8b30a7f commit 112e0a7

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

+stdlib/+sys/disk_available.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
function [t, cmd] = disk_available(p)
1+
function [t, cmd] = disk_available(file)
22

33
t = [];
44

55
if ispc()
6-
cmd = sprintf('pwsh -c ([System.IO.DriveInfo]''%s'').AvailableFreeSpace', stdlib.absolute(p));
7-
% r = stdlib.root_name(stdlib.absolute(p));
6+
cmd = sprintf('pwsh -c ([System.IO.DriveInfo][System.IO.Path]::GetFullPath(''%s'')).AvailableFreeSpace', file);
7+
% r = stdlib.root_name(stdlib.absolute(file));
88
% cmd = sprintf('pwsh -c (Get-CimInstance -ClassName Win32_LogicalDisk -Filter \"DeviceID=''%s''\").FreeSpace', r);
99
% slower
10-
% dl = extractBefore(stdlib.absolute(p), 2);
10+
% dl = extractBefore(stdlib.absolute(file), 2);
1111
% cmd = sprintf('pwsh -c "(Get-Volume -DriveLetter ''%s'').SizeRemaining"', dl);
1212
% slowest
1313
elseif ismac()
14-
cmd = sprintf('df -k "%s" | awk ''NR==2 {print $4*1024}''', p);
14+
cmd = sprintf('df -k "%s" | awk ''NR==2 {print $4*1024}''', file);
1515
else
16-
cmd = sprintf('df -B1 "%s" | awk ''NR==2 {print $4}''', p);
16+
cmd = sprintf('df -B1 "%s" | awk ''NR==2 {print $4}''', file);
1717
end
1818

19-
if stdlib.exists(p)
19+
if stdlib.exists(file)
2020
[s, t] = system(cmd);
2121
if s == 0
2222
t = str2double(t);

+stdlib/+sys/disk_capacity.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
function [t, cmd] = disk_capacity(p)
1+
function [t, cmd] = disk_capacity(file)
22

33
t = [];
44

55
if ispc()
6-
cmd = sprintf('pwsh -c ([System.IO.DriveInfo]''%s'').TotalSize', stdlib.absolute(p));
7-
% dl = extractBefore(stdlib.absolute(p), 2);
6+
cmd = sprintf('pwsh -c ([System.IO.DriveInfo][System.IO.Path]::GetFullPath(''%s'')).TotalSize', file);
7+
% dl = extractBefore(stdlib.absolute(file), 2);
88
% cmd = sprintf('pwsh -c "(Get-Volume -DriveLetter ''%s'').Size"', dl);
99
% slower
1010
elseif ismac()
11-
cmd = sprintf('df -k "%s" | awk ''NR==2 {print $2*1024}''', p);
11+
cmd = sprintf('df -k "%s" | awk ''NR==2 {print $2*1024}''', file);
1212
else
13-
cmd = sprintf('df -B1 "%s" | awk ''NR==2 {print $2}''', p);
13+
cmd = sprintf('df -B1 "%s" | awk ''NR==2 {print $2}''', file);
1414
end
1515

16-
if stdlib.exists(p)
16+
if stdlib.exists(file)
1717
[s, t] = system(cmd);
1818
if s == 0
1919
t = str2double(t);

+stdlib/+sys/filesystem_type.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
t = '';
77

88
if ispc()
9-
dl = extractBefore(stdlib.absolute(file), 2);
10-
cmd = sprintf('pwsh -c "(Get-Volume -DriveLetter ''%s'').FileSystem"', dl);
9+
cmd = sprintf('pwsh -c ([System.IO.DriveInfo][System.IO.Path]::GetFullPath(''%s'')).DriveFormat', file);
10+
% dl = extractBefore(stdlib.absolute(file), 2);
11+
% cmd = sprintf('pwsh -c "(Get-Volume -DriveLetter ''%s'').FileSystem"', dl);
12+
% slower
1113
elseif ismac()
1214
cmd = sprintf('df -aHY "%s" | awk ''NR==2 {print $2}''', file);
1315
else

0 commit comments

Comments
 (0)