Added fileCopy and fileMove functions to replace os.rename which doesn't work across filesystems. Added an error message if the move isn't accomplished so that the user knows what happened. Updated translations to reflect changes.

This commit is contained in:
Bill Ferguson
2016-08-23 00:09:27 -04:00
parent 0c0f97560e
commit 74e546c2ce
2 changed files with 56 additions and 11 deletions

View File

@@ -26,14 +26,18 @@ msgstr ""
msgid "Export Image %i/%i"
msgstr "Exportiere Bild %i/%i"
#: gimp.lua:194
#: gimp.lua:221
msgid "Unable to move edited file into collection. Leaving it as %s"
msgstr "Kann nicht bearbeitete Datei in Sammlung zu bewegen. Wenn sie unverändert %s"
#: gimp.lua:228
msgid "GIMP not found"
msgstr "GIMP nicht gefunden"
#: gimp.lua:209
#: gimp.lua:243
msgid "Launching GIMP..."
msgstr "Starten von GIMP"
#: gimp.lua:254
#: gimp.lua:290
msgid "Edit with GIMP"
msgstr "Bearbeiten mit GIMP"

View File

@@ -56,6 +56,11 @@
BUGS, COMMENTS, SUGGESTIONS
* Send to Bill Ferguson, wpferguson@gmail.com
CHANGES
* 20160823 - os.rename doesn't work across filesystems. Added fileCopy and fileMove functions to move the file
from the temporary location to the collection location irregardless of what filesystem it is on. If an
issue is encountered, a message is printed back to the UI so the user isn't left wondering what happened.
]]
local dt = require "darktable"
@@ -189,6 +194,40 @@ local function show_status(storage, image, format, filename,
dt.print(string.format(_("Export Image %i/%i"), number, total))
end
local function fileCopy(fromFile, toFile)
local result = nil
local fileIn, err = io.open(fromFile, 'rb')
if fileIn then
local fileOut, errr = io.open(toFile, 'w')
if fileOut then
local content = fileIn:read(4096)
while content do
fileOut:write(content)
content = fileIn:read(4096)
end
result = true
fileIn:close()
fileOut:close()
else
dt.print_error("fileCopy Error: " .. errr)
end
else
dt.print_error("fileCopy Error: " .. err)
end
return result
end
local function fileMove(fromFile, toFile)
local result = fileCopy(fromFile, toFile)
if result then
os.remove(fromFile)
else
dt.print_error("fileMove Error: Unable to copy " .. fromFile .. " to " .. toFile .. ". Leaving " .. fromFile .. " in place.")
dt.print(string.format(_("Unable to move edited file into collection. Leaving it as %s"), fromFile))
end
return result
end
local function gimp_edit(storage, image_table, extra_data) --finalize
if not checkIfBinExists("gimp") then
dt.print_error(_("GIMP not found"))
@@ -233,17 +272,19 @@ local function gimp_edit(storage, image_table, extra_data) --finalize
end
dt.print_error("moving " .. exported_image .. " to " .. myimage_name)
result = os.rename(exported_image, myimage_name)
local result = fileMove(exported_image, myimage_name)
dt.print_error("importing file")
local myimage = dt.database.import(myimage_name)
if result then
dt.print_error("importing file")
local myimage = dt.database.import(myimage_name)
groupIfNotMember(image, myimage)
groupIfNotMember(image, myimage)
for _,tag in pairs(dt.tags.get_tags(image)) do
if not (string.sub(tag.name,1,9) == "darktable") then
dt.print_error("attaching tag")
dt.tags.attach(tag,myimage)
for _,tag in pairs(dt.tags.get_tags(image)) do
if not (string.sub(tag.name,1,9) == "darktable") then
dt.print_error("attaching tag")
dt.tags.attach(tag,myimage)
end
end
end
end