darktable-org / lua-scripts

155 stars 110 forks source link

Function dtutils_file.executable_path_widget() fails in Windows #229

Closed Mark-64 closed 4 years ago

Mark-64 commented 4 years ago

The library function dtutils_file.executable_path_widget() registers a null string in preferences whenever the filepath contains spaces. In turn, this causes the function dtutils_file.check_if_bin_exists() to return an incorrect value. For example, this misbehaviour is visible in gimp.lua, which in fact doesn't work in Windows.

Tested with DT 3.1 git master on Windows 10

Mark-64 commented 4 years ago

Digging in, it seems to me the bug is in

function dtutils_file.check_if_file_exists(filepath)
  local result = false
  if (dt.configuration.running_os == 'windows') then
    filepath = string.gsub(filepath, '[\\/]+', '\\')
    local p = io.popen("if exist " .. filepath .. " (echo 'yes') else (echo 'no')")
...

while it should be

function dtutils_file.check_if_file_exists(filepath)
  local result = false
  if (dt.configuration.running_os == 'windows') then
    filepath = string.gsub(filepath, '[\\/]+', '\\')
    local p = io.popen("if exist " .. dtutils_file.sanitize_filename(filepath) .. " (echo 'yes') else (echo 'no')")
...

Actually in the Linux branch of the same function the filepath is sanitized before checking for existance.

I will do a PR

Mark-64 commented 4 years ago

Created PR