@@ -194,16 +194,58 @@ local function show_status(storage, image, format, filename,
194
194
dt .print (string.format (_ (" Export Image %i/%i" ), number , total ))
195
195
end
196
196
197
- local function fileMove (fromFile , toFile )
198
- local result = os.execute (" mv '" .. fromFile .. " ' '" .. toFile .. " '" )
199
- dt .print_error (" result is " .. tostring (result ))
197
+ local function fileCopy (fromFile , toFile )
198
+ local result = nil
199
+ -- if cp exists, use it
200
+ if checkIfBinExists (" cp" ) then
201
+ result = os.execute (" cp '" .. fromFile .. " ' '" .. toFile .. " '" )
202
+ end
203
+ -- if cp was not present, or if cp failed, then a pure lua solution
200
204
if not result then
201
- dt .print_error (" fileMove Error: Unable to copy " .. fromFile .. " to " .. toFile .. " . Leaving " .. fromFile .. " in place." )
202
- dt .print (string.format (_ (" Unable to move edited file into collection. Leaving it as %s" ), fromFile ))
205
+ local fileIn , err = io.open (fromFile , ' rb' )
206
+ if fileIn then
207
+ local fileOut , errr = io.open (toFile , ' w' )
208
+ if fileOut then
209
+ local content = fileIn :read (4096 )
210
+ while content do
211
+ fileOut :write (content )
212
+ content = fileIn :read (4096 )
213
+ end
214
+ result = true
215
+ fileIn :close ()
216
+ fileOut :close ()
217
+ else
218
+ dt .print_error (" fileCopy Error: " .. errr )
219
+ end
220
+ else
221
+ dt .print_error (" fileCopy Error: " .. err )
222
+ end
203
223
end
204
224
return result
205
225
end
206
226
227
+ local function fileMove (fromFile , toFile )
228
+ local success = os.rename (fromFile , toFile )
229
+ if not success then
230
+ -- an error occurred, so let's try using the operating system function
231
+ if checkIfBinExists (" mv" ) then
232
+ success = os.execute (" mv '" .. fromFile .. " ' '" .. toFile .. " '" )
233
+ end
234
+ -- if the mv didn't exist or succeed, then...
235
+ if not success then
236
+ -- pure lua solution
237
+ success = fileCopy (fromFile , toFile )
238
+ if success then
239
+ os.remove (fromFile )
240
+ else
241
+ dt .print_error (" fileMove Error: Unable to move " .. fromFile .. " to " .. toFile .. " . Leaving " .. fromFile .. " in place." )
242
+ dt .print (string.format (_ (" Unable to move edited file into collection. Leaving it as %s" ), fromFile ))
243
+ end
244
+ end
245
+ end
246
+ return success -- nil on error, some value if success
247
+ end
248
+
207
249
local function gimp_edit (storage , image_table , extra_data ) -- finalize
208
250
if not checkIfBinExists (" gimp" ) then
209
251
dt .print_error (_ (" GIMP not found" ))
0 commit comments