[nautilus] file-operations: deduplicate code



commit 80ebc12c491c4fd9f239f79146c4ef562cd29b19
Author: Ernestas Kulik <ernestask gnome org>
Date:   Mon May 15 17:17:04 2017 +0300

    file-operations: deduplicate code
    
    Some duplicate code can be removed by refactoring
    mark_desktop_file_executable().
    
    https://bugzilla.gnome.org/show_bug.cgi?id=782658

 src/nautilus-file-operations.c |  108 +++++++++++++---------------------------
 1 files changed, 35 insertions(+), 73 deletions(-)
---
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index 366da41..3cb9335 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -7983,9 +7983,10 @@ mark_desktop_file_executable (CommonJob    *common,
                               gboolean      interactive)
 {
     GError *error;
-    guint32 current_perms, new_perms;
+    guint32 current_perms;
+    guint32 new_perms;
     int response;
-    GFileInfo *info;
+    g_autoptr (GFileInfo) info = NULL;
 
 retry:
 
@@ -7997,86 +7998,47 @@ retry:
                               common->cancellable,
                               &error);
 
-    if (info == NULL)
+    if (info != NULL && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE))
     {
-        if (interactive)
-        {
-            response = run_error (common,
-                                  g_strdup (_("Unable to mark launcher trusted (executable)")),
-                                  error->message,
-                                  NULL,
-                                  FALSE,
-                                  CANCEL, RETRY,
-                                  NULL);
-        }
-        else
-        {
-            response = 0;
-        }
+        current_perms = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
+        new_perms = current_perms | S_IXGRP | S_IXUSR | S_IXOTH;
 
-        if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+        if (current_perms != new_perms)
         {
-            abort_job (common);
+            g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_MODE,
+                                         new_perms, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+                                         common->cancellable, &error);
         }
-        else if (response == 1)
-        {
-            goto retry;
-        }
-        else
-        {
-            g_assert_not_reached ();
-        }
-
-        goto out;
     }
 
-
-    if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_UNIX_MODE))
+    if (interactive && error != NULL)
     {
-        current_perms = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_UNIX_MODE);
-        new_perms = current_perms | S_IXGRP | S_IXUSR | S_IXOTH;
-
-        if ((current_perms != new_perms) &&
-            !g_file_set_attribute_uint32 (file, G_FILE_ATTRIBUTE_UNIX_MODE,
-                                          new_perms, G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-                                          common->cancellable, &error))
-        {
-            g_object_unref (info);
-
-            if (interactive)
-            {
-                response = run_error (common,
-                                      g_strdup (_("Unable to mark launcher trusted (executable)")),
-                                      error->message,
-                                      NULL,
-                                      FALSE,
-                                      CANCEL, RETRY,
-                                      NULL);
-            }
-            else
-            {
-                response = 0;
-            }
-
-            if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
-            {
-                abort_job (common);
-            }
-            else if (response == 1)
-            {
-                goto retry;
-            }
-            else
-            {
-                g_assert_not_reached ();
-            }
+        response = run_error (common,
+                              g_strdup (_("Unable to mark launcher trusted (executable)")),
+                              error->message,
+                              NULL,
+                              FALSE,
+                              CANCEL, RETRY,
+                              NULL);
+    }
+    else
+    {
+        response = 0;
+    }
 
-            goto out;
-        }
+    if (response == 0 || response == GTK_RESPONSE_DELETE_EVENT)
+    {
+        abort_job (common);
+    }
+    else if (response == 1)
+    {
+        g_object_unref (info);
+        goto retry;
+    }
+    else
+    {
+        g_assert_not_reached ();
     }
-    g_object_unref (info);
-out:
-    ;
 }
 
 static void


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