[gimp] plug-ins: make mail more robust.



commit 91bde62b08c80757b0a154130b5a4c8231043105
Author: Jehan <jehan girinstud io>
Date:   Sat Aug 17 00:41:00 2019 +0200

    plug-ins: make mail more robust.
    
    I got a 'Invalid cross-device link' error (errno 18) on my system. Let's
    add some redundancy and try g_file_move() if g_rename() failed.
    This at least fixed my case.

 plug-ins/common/mail.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
---
diff --git a/plug-ins/common/mail.c b/plug-ins/common/mail.c
index 90abff96cb..378c7b5cce 100644
--- a/plug-ins/common/mail.c
+++ b/plug-ins/common/mail.c
@@ -439,7 +439,27 @@ send_image (const gchar *filename,
 
   filepath = g_build_filename (gimp_file_get_utf8_name (tmp_dir),
                                mail_info.filename, NULL);
-  g_rename (tmpname, filepath);
+  if (g_rename (tmpname, filepath) == -1)
+    {
+      /* But on some system, I got an 'Invalid cross-device link' errno
+       * with g_rename().
+       * On the other hand, g_file_move() seems to be more robust.
+       */
+      GFile *source = g_file_new_for_path (tmpname);
+      GFile *target = g_file_new_for_path (filepath);
+
+      if (! g_file_move (source, target, G_FILE_COPY_NONE, NULL, NULL, NULL, &error))
+        {
+          g_message ("%s", error->message);
+          g_clear_error (&error);
+          g_object_unref (source);
+          g_object_unref (target);
+          goto error;
+        }
+
+      g_object_unref (source);
+      g_object_unref (target);
+    }
 
   mailcmd[0] = g_strdup ("xdg-email");
   mailcmd[1] = "--attach";


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]