Skip to content

Commit 9f2dbef

Browse files
committed
lib/dtutils/system added local helper function quote_windows_command() to
wrap a windows command in quotes. Added a sanitize step to windows_external_command() plus quote_windows_command() to deal with all the windows username possibilities
1 parent 2abb83b commit 9f2dbef

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/dtutils/system.lua

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local dtutils_system = {}
22

33
local dt = require "darktable"
4+
local ds = require "lib/dtutils.string"
45

56
dtutils_system.libdoc = {
67
Name = [[dtutils.system]],
@@ -50,9 +51,9 @@ function dtutils_system.external_command(command)
5051
local result = nil
5152

5253
if dt.configuration.running_os == "windows" then
53-
result = dtutils_system.windows_command(command)
54+
result = dtutils_system.windows_command(ds.sanitize(command))
5455
else
55-
result = dt.control.execute(command)
56+
result = dt.control.execute(ds.sanitize(command))
5657
end
5758

5859
return result
@@ -77,15 +78,20 @@ dtutils_system.libdoc.functions["windows_command"] = {
7778
Copyright = [[]],
7879
}
7980

81+
local function quote_windows_command(command)
82+
return "\"" .. command .. "\""
83+
end
84+
8085
function dtutils_system.windows_command(command)
8186
local result = 1
8287

83-
local fname = dt.configuration.tmp_dir .. "/run_command.bat"
88+
local fname = ds.sanitize(dt.configuration.tmp_dir .. "/run_command.bat")
8489

8590
local file = io.open(fname, "w")
8691
if file then
8792
dt.print_log("opened file")
8893
command = string.gsub(command, "%%", "%%%%") -- escape % from windows shell
94+
command = quote_windows-command(command)
8995
file:write(command)
9096
file:close()
9197

@@ -149,7 +155,7 @@ dtutils_system.libdoc.functions["os_execute"] = {
149155

150156
function dtutils_system.os_execute(cmd)
151157
if dt.configuration.running_os == "windows" then
152-
cmd = "\"" .. cmd .. "\""
158+
cmd = quote_windows_command(cmd)
153159
end
154160
return os.execute(cmd)
155161
end
@@ -174,7 +180,7 @@ dtutils_system.libdoc.functions["io_popen"] = {
174180

175181
function dtutils_system.io_popen(cmd)
176182
if dt.configuration.running_os == "windows" then
177-
cmd = "\"" .. cmd .. "\""
183+
cmd = quote_windows_command(cmd)
178184
end
179185
return io.popen(cmd)
180186
end

0 commit comments

Comments
 (0)