Skip to content

Commit f69455b

Browse files
authored
Merge pull request darktable-org#65 from wpferguson/master
Added fileCopy and fileMove functions to replace os.rename which does…
2 parents 4ed6dc2 + f7ce368 commit f69455b

File tree

2 files changed

+75
-12
lines changed

2 files changed

+75
-12
lines changed

contrib/de_DE/LC_MESSAGES/gimp.po

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +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:194
29+
#: gimp.lua:242
30+
msgid "Unable to move edited file into collection. Leaving it as %s"
31+
msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitete Datei ist %s"
32+
33+
#: gimp.lua:251
3034
msgid "GIMP not found"
3135
msgstr "GIMP nicht gefunden"
3236

33-
#: gimp.lua:209
37+
#: gimp.lua:266
3438
msgid "Launching GIMP..."
3539
msgstr "Starten von GIMP"
3640

37-
#: gimp.lua:254
41+
#: gimp.lua:313
3842
msgid "Edit with GIMP"
3943
msgstr "Bearbeiten mit GIMP"

contrib/gimp.lua

Lines changed: 67 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
5757
BUGS, COMMENTS, SUGGESTIONS
5858
* Send to Bill Ferguson, [email protected]
59+
60+
CHANGES
61+
* 20160823 - os.rename doesn't work across filesystems. Added fileCopy and fileMove functions to move the file
62+
from the temporary location to the collection location irregardless of what filesystem it is on. If an
63+
issue is encountered, a message is printed back to the UI so the user isn't left wondering what happened.
5964
]]
6065

6166
local dt = require "darktable"
@@ -189,6 +194,58 @@ local function show_status(storage, image, format, filename,
189194
dt.print(string.format(_("Export Image %i/%i"), number, total))
190195
end
191196

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
204+
if not result then
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
223+
end
224+
return result
225+
end
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+
192249
local function gimp_edit(storage, image_table, extra_data) --finalize
193250
if not checkIfBinExists("gimp") then
194251
dt.print_error(_("GIMP not found"))
@@ -233,17 +290,19 @@ local function gimp_edit(storage, image_table, extra_data) --finalize
233290
end
234291

235292
dt.print_error("moving " .. exported_image .. " to " .. myimage_name)
236-
result = os.rename(exported_image, myimage_name)
293+
local result = fileMove(exported_image, myimage_name)
237294

238-
dt.print_error("importing file")
239-
local myimage = dt.database.import(myimage_name)
295+
if result then
296+
dt.print_error("importing file")
297+
local myimage = dt.database.import(myimage_name)
240298

241-
groupIfNotMember(image, myimage)
299+
groupIfNotMember(image, myimage)
242300

243-
for _,tag in pairs(dt.tags.get_tags(image)) do
244-
if not (string.sub(tag.name,1,9) == "darktable") then
245-
dt.print_error("attaching tag")
246-
dt.tags.attach(tag,myimage)
301+
for _,tag in pairs(dt.tags.get_tags(image)) do
302+
if not (string.sub(tag.name,1,9) == "darktable") then
303+
dt.print_error("attaching tag")
304+
dt.tags.attach(tag,myimage)
305+
end
247306
end
248307
end
249308
end

0 commit comments

Comments
 (0)