From 74e546c2ce083e1e9d4f7709caab08694ef84a51 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Tue, 23 Aug 2016 00:09:27 -0400 Subject: [PATCH 1/7] 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. --- contrib/de_DE/LC_MESSAGES/gimp.po | 10 ++++-- contrib/gimp.lua | 57 ++++++++++++++++++++++++++----- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index 8b6dcbf..72e64df 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -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" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index a15ca6b..9e80b87 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -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 From 95e15fc40c0ad8b3309e847777b05c9e62c85e3f Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Tue, 23 Aug 2016 21:13:11 -0400 Subject: [PATCH 2/7] Changed poorly translated message to that suggested by supertobi, and took care of spacing issue. --- contrib/de_DE/LC_MESSAGES/gimp.po | 4 ++-- contrib/gimp.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index 72e64df..f536853 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -27,8 +27,8 @@ msgid "Export Image %i/%i" msgstr "Exportiere Bild %i/%i" #: 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" +msgid "Unable to move edited file into collection. Leaving it as %s" +msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitet Datei ist %s" #: gimp.lua:228 msgid "GIMP not found" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index 9e80b87..e885187 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -223,7 +223,7 @@ local function fileMove(fromFile, toFile) 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)) + dt.print(string.format(_("Unable to move edited file into collection. Leaving it as %s"), fromFile)) end return result end From 3b42503bd373ad6efb445a4f9b209673fb30e92e Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Tue, 23 Aug 2016 21:14:39 -0400 Subject: [PATCH 3/7] Removed extra end statement --- contrib/geo_uri.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/geo_uri.lua b/contrib/geo_uri.lua index d86018c..e7edefd 100644 --- a/contrib/geo_uri.lua +++ b/contrib/geo_uri.lua @@ -70,7 +70,6 @@ local function openLocationInGnomeMaps() lat1 = image.latitude; lon1 = image.longitude; break - end end local startCommand From 21f31b403bfb160d25390afcd49cd15ec2631b59 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Thu, 25 Aug 2016 22:49:59 -0400 Subject: [PATCH 4/7] Recoded fileMove to use os.execute and the system mv command. Removed fileCopy as it was no longer needed. --- contrib/de_DE/LC_MESSAGES/gimp.po | 8 ++++---- contrib/gimp.lua | 30 +++--------------------------- 2 files changed, 7 insertions(+), 31 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index f536853..f291f1b 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -26,18 +26,18 @@ msgstr "" msgid "Export Image %i/%i" msgstr "Exportiere Bild %i/%i" -#: gimp.lua:221 +#: gimp.lua:202 msgid "Unable to move edited file into collection. Leaving it as %s" msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitet Datei ist %s" -#: gimp.lua:228 +#: gimp.lua:209 msgid "GIMP not found" msgstr "GIMP nicht gefunden" -#: gimp.lua:243 +#: gimp.lua:224 msgid "Launching GIMP..." msgstr "Starten von GIMP" -#: gimp.lua:290 +#: gimp.lua:271 msgid "Edit with GIMP" msgstr "Bearbeiten mit GIMP" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index e885187..f90db1d 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -194,34 +194,10 @@ 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 + local result = os.execute("mv '" .. fromFile .. "' '" .. toFile .. "'") + dt.print_error("result is " .. tostring(result)) + if not result then 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 From 549e9ccd0b27de48780ac10c52588929bee180c7 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Wed, 31 Aug 2016 20:18:29 -0400 Subject: [PATCH 5/7] 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 --- contrib/de_DE/LC_MESSAGES/gimp.po | 10 +++--- contrib/gimp.lua | 52 ++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index f291f1b..1a16cb7 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -21,23 +21,23 @@ msgstr "" "dngettext:2,3\n" "X-Poedit-Basepath: .\n" -#: gimp.lua:189 +#: gimp.lua:194 #, lua-format msgid "Export Image %i/%i" msgstr "Exportiere Bild %i/%i" -#: gimp.lua:202 +#: gimp.lua:242 msgid "Unable to move edited file into collection. Leaving it as %s" msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitet Datei ist %s" -#: gimp.lua:209 +#: gimp.lua:251 msgid "GIMP not found" msgstr "GIMP nicht gefunden" -#: gimp.lua:224 +#: gimp.lua:266 msgid "Launching GIMP..." msgstr "Starten von GIMP" -#: gimp.lua:271 +#: gimp.lua:313 msgid "Edit with GIMP" msgstr "Bearbeiten mit GIMP" diff --git a/contrib/gimp.lua b/contrib/gimp.lua index f90db1d..61c4fdb 100644 --- a/contrib/gimp.lua +++ b/contrib/gimp.lua @@ -194,16 +194,58 @@ local function show_status(storage, image, format, filename, dt.print(string.format(_("Export Image %i/%i"), number, total)) end -local function fileMove(fromFile, toFile) - local result = os.execute("mv '" .. fromFile .. "' '" .. toFile .. "'") - dt.print_error("result is " .. tostring(result)) +local function fileCopy(fromFile, toFile) + local result = nil + -- if cp exists, use it + if checkIfBinExists("cp") then + result = os.execute("cp '" .. fromFile .. "' '" .. toFile .. "'") + end + -- if cp was not present, or if cp failed, then a pure lua solution if not result then - 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)) + 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 end return result end +local function fileMove(fromFile, toFile) + local success = os.rename(fromFile, toFile) + if not success then + -- an error occurred, so let's try using the operating system function + if checkIfBinExists("mv") then + success = os.execute("mv '" .. fromFile .. "' '" .. toFile .. "'") + end + -- if the mv didn't exist or succeed, then... + if not success then + -- pure lua solution + success = fileCopy(fromFile, toFile) + if success then + os.remove(fromFile) + else + dt.print_error("fileMove Error: Unable to move " .. fromFile .. " to " .. toFile .. ". Leaving " .. fromFile .. " in place.") + dt.print(string.format(_("Unable to move edited file into collection. Leaving it as %s"), fromFile)) + end + end + end + return success -- nil on error, some value if success +end + local function gimp_edit(storage, image_table, extra_data) --finalize if not checkIfBinExists("gimp") then dt.print_error(_("GIMP not found")) From 168236780d254fc1b69cf9ce3a4f9979a4a1a60c Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Sun, 4 Sep 2016 11:42:27 -0400 Subject: [PATCH 6/7] Incorporated supertobi's correction to the translations --- contrib/de_DE/LC_MESSAGES/gimp.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/de_DE/LC_MESSAGES/gimp.po b/contrib/de_DE/LC_MESSAGES/gimp.po index 1a16cb7..1df4443 100644 --- a/contrib/de_DE/LC_MESSAGES/gimp.po +++ b/contrib/de_DE/LC_MESSAGES/gimp.po @@ -28,7 +28,7 @@ msgstr "Exportiere Bild %i/%i" #: gimp.lua:242 msgid "Unable to move edited file into collection. Leaving it as %s" -msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitet Datei ist %s" +msgstr "Die bearbeitete Datei kann nicht in die Sammlung aufgenommen werden. Bearbeitete Datei ist %s" #: gimp.lua:251 msgid "GIMP not found" From f7ce368b289623cddbd2a9b9f9da8bf9075c6c08 Mon Sep 17 00:00:00 2001 From: Bill Ferguson Date: Mon, 5 Sep 2016 13:49:47 -0400 Subject: [PATCH 7/7] Reverted contrib/geo_uri.lua to previous version so that I can add it in it's own pull request. --- contrib/geo_uri.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/geo_uri.lua b/contrib/geo_uri.lua index e7edefd..d86018c 100644 --- a/contrib/geo_uri.lua +++ b/contrib/geo_uri.lua @@ -70,6 +70,7 @@ local function openLocationInGnomeMaps() lat1 = image.latitude; lon1 = image.longitude; break + end end local startCommand