|
56 | 56 |
|
57 | 57 | BUGS, COMMENTS, SUGGESTIONS
|
58 | 58 | * 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. |
59 | 64 | ]]
|
60 | 65 |
|
61 | 66 | local dt = require "darktable"
|
@@ -189,6 +194,58 @@ local function show_status(storage, image, format, filename,
|
189 | 194 | dt.print(string.format(_("Export Image %i/%i"), number, total))
|
190 | 195 | end
|
191 | 196 |
|
| 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 | + |
192 | 249 | local function gimp_edit(storage, image_table, extra_data) --finalize
|
193 | 250 | if not checkIfBinExists("gimp") then
|
194 | 251 | dt.print_error(_("GIMP not found"))
|
@@ -233,17 +290,19 @@ local function gimp_edit(storage, image_table, extra_data) --finalize
|
233 | 290 | end
|
234 | 291 |
|
235 | 292 | 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) |
237 | 294 |
|
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) |
240 | 298 |
|
241 |
| - groupIfNotMember(image, myimage) |
| 299 | + groupIfNotMember(image, myimage) |
242 | 300 |
|
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 |
247 | 306 | end
|
248 | 307 | end
|
249 | 308 | end
|
|
0 commit comments