64
64
]]
65
65
66
66
local dt = require " darktable"
67
+ local df = require " lib/dtutils.file"
67
68
require " official/yield"
68
-
69
69
local gettext = dt .gettext
70
70
71
71
dt .configuration .check_version (... ,{3 ,0 ,0 },{4 ,0 ,0 },{5 ,0 ,0 })
@@ -104,21 +104,6 @@ local function _(msgid)
104
104
return gettext .dgettext (" gimp" , msgid )
105
105
end
106
106
107
- local function checkIfBinExists (bin )
108
- local handle = io.popen (" which " .. bin )
109
- local result = handle :read ()
110
- local ret
111
- handle :close ()
112
- if (result ) then
113
- dt .print_error (" true checkIfBinExists: " .. bin )
114
- ret = true
115
- else
116
- dt .print_error (bin .. " not found" )
117
- ret = false
118
- end
119
- return ret
120
- end
121
-
122
107
-- Thanks Tobias Jakobs for the idea and the correction
123
108
function checkIfFileExists (filepath )
124
109
local file = io.open (filepath ," r" )
199
184
local function fileCopy (fromFile , toFile )
200
185
local result = nil
201
186
-- if cp exists, use it
202
- if checkIfBinExists (" cp" ) then
187
+ if df . check_if_bin_exists (" cp" ) then
203
188
result = os.execute (" cp '" .. fromFile .. " ' '" .. toFile .. " '" )
204
189
end
205
190
-- if cp was not present, or if cp failed, then a pure lua solution
@@ -230,7 +215,7 @@ local function fileMove(fromFile, toFile)
230
215
local success = os.rename (fromFile , toFile )
231
216
if not success then
232
217
-- an error occurred, so let's try using the operating system function
233
- if checkIfBinExists (" mv" ) then
218
+ if df . check_if_bin_exists (" mv" ) then
234
219
success = os.execute (" mv '" .. fromFile .. " ' '" .. toFile .. " '" )
235
220
end
236
221
-- if the mv didn't exist or succeed, then...
@@ -249,7 +234,7 @@ local function fileMove(fromFile, toFile)
249
234
end
250
235
251
236
local function gimp_edit (storage , image_table , extra_data ) -- finalize
252
- if not checkIfBinExists (" gimp" ) then
237
+ if not df . check_if_bin_exists (" gimp" ) then
253
238
dt .print_error (_ (" GIMP not found" ))
254
239
return
255
240
end
0 commit comments