Skip to content

Commit 8818965

Browse files
committed
more sprintf
1 parent 601c931 commit 8818965

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

+stdlib/+sys/get_owner.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
if ~stdlib.exists(p), return, end
55

66
if ispc()
7-
cmd = "pwsh -c (Get-Acl -Path '" + p + "').Owner";
7+
cmd = sprintf('pwsh -c (Get-Acl -Path "%s").Owner', p);
88
elseif ismac()
99
cmd = sprintf('stat -f %%Su "%s"', p);
1010
else

+stdlib/+sys/get_username.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
if ispc()
44
cmd = "whoami";
55
else
6-
cmd = "id -un"; % POSIX compliant command to get username
6+
cmd = "id -un";
77
end
88
[s, n] = system(cmd);
99

1010
if s == 0
11-
n = string(strtrim(n)); % Remove any trailing newline or spaces
11+
n = string(strtrim(n));
1212
else
1313
warning("Failed to get username from system %s: %s", cmd, n);
1414
n = string.empty;

+stdlib/+sys/is_admin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
if s ~= 0
1111
warning("stdlib:is_admin:RuntimeError", "Failed to execute command '%s': %s", cmd, r);
1212
y = false;
13-
return;
13+
return
1414
end
1515

1616
r = string(strip(r));

+stdlib/+sys/is_mount.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@
44
if ispc()
55
if any(ismember(filepath, ["/", "\"])) || ...
66
(endsWith(filepath, ["/", "\"]) && isfolder(filepath) && filepath == stdlib.root(filepath))
7-
y = true;
7+
y = true;
88
return
99
end
10-
cmd = strcat('pwsh -c "(Get-Item -Path ''', filepath, ''').Attributes.ToString().Contains(''ReparsePoint'')"');
10+
cmd = sprintf('pwsh -c "(Get-Item -Path ''%s'').Attributes.ToString().Contains(''ReparsePoint'')"', filepath);
1111
elseif ismac()
1212
if filepath == "/"
1313
y = true;
1414
return
1515
end
16-
cmd = "[ $(stat -f %d " + filepath + ") != $(stat -f %d " + stdlib.parent(filepath) + ")]";
16+
cmd = sprintf('[ $(stat -f %%d "%s") != $(stat -f %%d "%s")]', ...
17+
filepath, stdlib.parent(filepath));
1718
else
18-
cmd = "mountpoint -q " + filepath;
19+
cmd = sprintf('mountpoint -q "%s"', filepath);
1920
end
2021

2122
[s, m] = system(cmd);
2223

2324
if ispc()
2425
y = s == 0 && m == "True";
25-
else
26+
else
2627
y = s == 0;
2728
end
2829

+stdlib/+sys/is_removable.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
if ispc()
66
drive = stdlib.root_name(filepath);
7-
cmd1 = strcat('wmic logicaldisk where "DeviceID=''', drive, '''" get DriveType');
7+
cmd1 = sprintf('wmic logicaldisk where "DeviceID=''%s''" get DriveType', drive);
88
else
99
cmd1 = sprintf('df "%s" | tail -n 1 | awk ''{print $1}''', filepath);
1010
end
@@ -22,18 +22,18 @@
2222

2323
elseif ismac()
2424

25-
cmd2 = ['diskutil info ', m1];
25+
cmd2 = sprintf('diskutil info "%s"', m1);
2626
[s2, m2] = system(cmd2);
2727
y = s2 == 0 && contains(m2, "Removable Media:" + whitespacePattern + "Removable");
2828

2929
else
3030

3131
dev = strtrim(extractAfter(m1, '/dev/'));
32-
f1 = strcat('/sys/class/block/', dev, '/removable');
32+
f1 = sprintf('/sys/class/block/%s/removable', dev);
3333
if isfile(f1)
3434
y = strtrim(fileread(f1)) == "1";
3535
end
3636

3737
end
3838

39-
end
39+
end

+stdlib/+sys/read_symlink.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
if ~stdlib.is_symlink(p), return, end
66

77
if isunix()
8-
cmd = sprintf('readlink -fn %s', p);
8+
cmd = sprintf('readlink -fn "%s"', p);
99
else
1010
cmd = sprintf('pwsh -command "(Get-Item -Path %s).Target"', p);
1111
end

+stdlib/file_size.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
s = [];
1414

1515
if ~isfile(p)
16-
return;
16+
return
1717
end
1818

1919
d = dir(p);

0 commit comments

Comments
 (0)