Skip to content

Commit 549e9cc

Browse files
author
Bill Ferguson
committed
Changed fileMove per discussion to use os.rename first, os.execute(mv... second, and a lua solution third. The lua solution includes fileCopy with attempts os.execute(cp... first, then does a pure lua copy if that doesn't succeed
1 parent 21f31b4 commit 549e9cc

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

contrib/de_DE/LC_MESSAGES/gimp.po

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ msgstr ""
2121
"dngettext:2,3\n"
2222
"X-Poedit-Basepath: .\n"
2323

24-
#: gimp.lua:189
24+
#: gimp.lua:194
2525
#, lua-format
2626
msgid "Export Image %i/%i"
2727
msgstr "Exportiere Bild %i/%i"
2828

29-
#: gimp.lua:202
29+
#: gimp.lua:242
3030
msgid "Unable to move edited file into collection. Leaving it as %s"
3131
msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitet Datei ist %s"
3232

33-
#: gimp.lua:209
33+
#: gimp.lua:251
3434
msgid "GIMP not found"
3535
msgstr "GIMP nicht gefunden"
3636

37-
#: gimp.lua:224
37+
#: gimp.lua:266
3838
msgid "Launching GIMP..."
3939
msgstr "Starten von GIMP"
4040

41-
#: gimp.lua:271
41+
#: gimp.lua:313
4242
msgid "Edit with GIMP"
4343
msgstr "Bearbeiten mit GIMP"

contrib/gimp.lua

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,58 @@ local function show_status(storage, image, format, filename,
194194
dt.print(string.format(_("Export Image %i/%i"), number, total))
195195
end
196196

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
200204
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
203223
end
204224
return result
205225
end
206226

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+
207249
local function gimp_edit(storage, image_table, extra_data) --finalize
208250
if not checkIfBinExists("gimp") then
209251
dt.print_error(_("GIMP not found"))

0 commit comments

Comments
 (0)