From 6bdc35fac30abf04a0c44bd6b26414b5cae33bfa Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Sun, 29 Dec 2024 21:18:37 +0530
Subject: [PATCH 01/17] Fix: retain special icons after rename

---
 thunar/thunar-file.c | 60 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 58 insertions(+), 2 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index c16b39286..8528e66fb 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -66,6 +66,7 @@
 #include "thunarx/thunarx.h"
 
 #include <gio/gio.h>
+#include <glib.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <libxfce4util/libxfce4util.h>
 
@@ -505,7 +506,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-    /* verify that nobody's watching the file anymore */
+  /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
@@ -1978,17 +1979,66 @@ thunar_file_rename (ThunarFile   *file,
   _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   /* try to rename the file */
+  gchar *old_name = g_strconcat ("/", thunar_file_get_basename (file), "\"", NULL);
+  gchar *old_icon = strdup (file->icon_name);
   renamed_file = g_file_set_display_name (file->gfile, name, cancellable, error);
 
   /* check if we succeeded */
   if (renamed_file != NULL)
     {
+      gchar  *config_file = NULL;
+      gchar  *contents = NULL;
+      gchar **lines = NULL;
+      gsize   length;
+
       /* replace GFile in ThunarFile for the renamed file */
       thunar_file_replace_file (file, renamed_file);
 
       /* reload file information */
       thunar_file_load (file, NULL, NULL);
 
+      file->icon_name = old_icon;
+
+      /* get the config file */
+      config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL);
+      if (g_file_get_contents (config_file, &contents, &length, NULL))
+        {
+          gchar *new_contents = NULL;
+          lines = g_strsplit (contents, "\n", -1);
+
+          for (int i = 0; lines[i] != NULL; i++)
+            {
+              /* if the current line has old_name mentioned, then replace it with new one */
+              if (g_str_has_suffix (lines[i], old_name))
+                {
+                  GString *line = g_string_new (lines[i]);
+                  gchar   *replace = g_strconcat ("/", name, "\"", NULL);
+
+                  g_string_replace (line, old_name, replace, 0);
+
+                  g_free (lines[i]);
+                  lines[i] = g_strdup (line->str);
+
+                  g_free (replace);
+                  g_string_free (line, TRUE);
+
+                  break;
+                }
+            }
+
+          /* reassemble the contents with the modified lines */
+          new_contents = g_strjoinv ("\n", lines);
+
+          /* write the new contents back to the config file */
+          if (!g_file_set_contents (config_file, new_contents, -1, NULL))
+            {
+              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Failed to write modified contents to %s", config_file);
+            }
+
+          g_free (new_contents);
+        }
+
+
       if (!called_from_job)
         {
           /* emit the file changed signal */
@@ -1996,9 +2046,15 @@ thunar_file_rename (ThunarFile   *file,
         }
 
       g_object_unref (renamed_file);
+      g_strfreev (lines);
+      g_free (contents);
+      g_free (config_file);
+      g_free (old_name);
+      g_free (old_icon);
       return TRUE;
     }
-
+  g_free (old_name);
+  g_free (old_icon);
   return FALSE;
 }
 
-- 
GitLab


From 6e5f06a9d8d82635c9280053b71af9edc61ee88f Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Tue, 7 Jan 2025 23:56:56 +0530
Subject: [PATCH 02/17] Fix: Move the assignment of icon_name at the end.

---
 thunar/thunar-file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 8528e66fb..458fb5e8e 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -1997,7 +1997,6 @@ thunar_file_rename (ThunarFile   *file,
       /* reload file information */
       thunar_file_load (file, NULL, NULL);
 
-      file->icon_name = old_icon;
 
       /* get the config file */
       config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL);
@@ -2044,13 +2043,13 @@ thunar_file_rename (ThunarFile   *file,
           /* emit the file changed signal */
           thunar_file_changed (file);
         }
+      file->icon_name = old_icon;
 
       g_object_unref (renamed_file);
       g_strfreev (lines);
       g_free (contents);
       g_free (config_file);
       g_free (old_name);
-      g_free (old_icon);
       return TRUE;
     }
   g_free (old_name);
-- 
GitLab


From 05a84c5bcb080a72f52bb9ff35553472b155a5bc Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Thu, 9 Jan 2025 19:07:59 +0530
Subject: [PATCH 03/17] Fix: Refactor config update logic and add
 thunar_file_get_icon_name call

Moved config update logic into gio-extensions.
Call thunar_file_get_icon_name in thunar_file_info_reload.
Reset user-dir cache before reading from cache.
---
 thunar/thunar-chooser-model.c  |  2 +-
 thunar/thunar-file.c           | 75 ++++++++------------------
 thunar/thunar-gio-extensions.c | 98 ++++++++++++++++++++++++++++++++++
 thunar/thunar-gio-extensions.h |  6 +++
 4 files changed, 128 insertions(+), 53 deletions(-)

diff --git a/thunar/thunar-chooser-model.c b/thunar/thunar-chooser-model.c
index b2cf063fd..3fe13f103 100644
--- a/thunar/thunar-chooser-model.c
+++ b/thunar/thunar-chooser-model.c
@@ -420,7 +420,7 @@ thunar_chooser_model_remove (ThunarChooserModel *model,
                                              error);
 
   /* try to delete the file */
-  if (delete &&succeed && g_app_info_delete (app_info))
+  if (delete && succeed && g_app_info_delete (app_info))
     {
       g_set_error (error, G_IO_ERROR,
                    G_IO_ERROR_FAILED,
diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 458fb5e8e..5c9772528 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -66,7 +66,6 @@
 #include "thunarx/thunarx.h"
 
 #include <gio/gio.h>
-#include <glib.h>
 #include <libxfce4ui/libxfce4ui.h>
 #include <libxfce4util/libxfce4util.h>
 
@@ -1116,6 +1115,12 @@ thunar_file_info_reload (ThunarFile   *file,
 
   /* cleanup */
   g_free (casefold);
+
+  /* restore icon name if needed */
+  if (file->icon_name == NULL)
+    {
+      thunar_file_get_icon_name (file, THUNAR_FILE_ICON_STATE_DEFAULT, gtk_icon_theme_get_default ());
+    }
 }
 
 
@@ -1979,17 +1984,19 @@ thunar_file_rename (ThunarFile   *file,
   _thunar_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
   /* try to rename the file */
-  gchar *old_name = g_strconcat ("/", thunar_file_get_basename (file), "\"", NULL);
-  gchar *old_icon = strdup (file->icon_name);
   renamed_file = g_file_set_display_name (file->gfile, name, cancellable, error);
 
   /* check if we succeeded */
   if (renamed_file != NULL)
     {
-      gchar  *config_file = NULL;
-      gchar  *contents = NULL;
-      gchar **lines = NULL;
-      gsize   length;
+      gchar *new_path;
+      gchar *old_path;
+      gchar *dir_name;
+      char   command[256];
+
+
+      old_path = g_file_get_path (thunar_file_get_file (file));
+      dir_name = thunar_get_user_dir_name (old_path);
 
       /* replace GFile in ThunarFile for the renamed file */
       thunar_file_replace_file (file, renamed_file);
@@ -1997,63 +2004,25 @@ thunar_file_rename (ThunarFile   *file,
       /* reload file information */
       thunar_file_load (file, NULL, NULL);
 
+      new_path = g_file_get_path (thunar_file_get_file (file));
 
-      /* get the config file */
-      config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL);
-      if (g_file_get_contents (config_file, &contents, &length, NULL))
-        {
-          gchar *new_contents = NULL;
-          lines = g_strsplit (contents, "\n", -1);
-
-          for (int i = 0; lines[i] != NULL; i++)
-            {
-              /* if the current line has old_name mentioned, then replace it with new one */
-              if (g_str_has_suffix (lines[i], old_name))
-                {
-                  GString *line = g_string_new (lines[i]);
-                  gchar   *replace = g_strconcat ("/", name, "\"", NULL);
-
-                  g_string_replace (line, old_name, replace, 0);
-
-                  g_free (lines[i]);
-                  lines[i] = g_strdup (line->str);
-
-                  g_free (replace);
-                  g_string_free (line, TRUE);
-
-                  break;
-                }
-            }
-
-          /* reassemble the contents with the modified lines */
-          new_contents = g_strjoinv ("\n", lines);
-
-          /* write the new contents back to the config file */
-          if (!g_file_set_contents (config_file, new_contents, -1, NULL))
-            {
-              g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, "Failed to write modified contents to %s", config_file);
-            }
-
-          g_free (new_contents);
-        }
+      /* update the config file */
+      snprintf (command, sizeof (command), "xdg-user-dirs-update --set %s %s", dir_name, new_path);
+      system (command);
 
+      /* Update the path in our hashtable */
+      thunar_user_dir_map_update (g_strdup (dir_name), g_strdup (new_path));
 
       if (!called_from_job)
         {
           /* emit the file changed signal */
           thunar_file_changed (file);
         }
-      file->icon_name = old_icon;
 
       g_object_unref (renamed_file);
-      g_strfreev (lines);
-      g_free (contents);
-      g_free (config_file);
-      g_free (old_name);
+      g_free (new_path);
       return TRUE;
     }
-  g_free (old_name);
-  g_free (old_icon);
   return FALSE;
 }
 
@@ -4172,6 +4141,8 @@ thunar_file_get_icon_name (ThunarFile         *file,
                 {
                   for (i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
                     {
+                      /* ensure latest cache */
+                      g_reload_user_special_dirs_cache ();
                       special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
                       if (special_dir != NULL
                           && strcmp (path, special_dir) == 0)
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index c208f1d8f..fb3af80c7 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -351,6 +351,104 @@ thunar_g_file_is_network (GFile *file)
 }
 
 
+static GHashTable *user_dirs_map = NULL;
+
+/*
+ * thunar_user_dir_map_update:
+ * @dir_name: user dir name to change the path
+ * @new_path: new path of user_dir
+ */
+void
+thunar_user_dir_map_update (gchar *dir_name, gchar *new_path)
+{
+  g_hash_table_replace (user_dirs_map, dir_name, new_path);
+}
+
+/* Cache the XDG directories with their names as keys and paths as values */
+void
+thunar_cache_user_dirs_paths (void)
+{
+  if (user_dirs_map == NULL)
+    {
+      user_dirs_map = g_hash_table_new (g_str_hash, g_str_equal);
+    }
+
+  gchar *config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL);
+  gchar *contents = NULL;
+  gsize  length;
+
+  if (g_file_get_contents (config_file, &contents, &length, NULL))
+    {
+      gchar **lines = g_strsplit (contents, "\n", -1);
+      for (int i = 0; lines[i] != NULL; i++)
+        {
+          if (g_str_has_prefix (lines[i], "XDG_"))
+            {
+              /* split xdg-dir and path */
+              gchar **split = g_strsplit (lines[i], "=", 2);
+
+              /* split xdg-dir by _ */
+              gchar **full_name = g_strsplit (split[0], "_", 3);
+
+              /* get the name */
+              gchar *key = g_strdup (full_name[1]);
+              gchar *path = g_strdup (split[1]);
+
+              /* Remove quotes and replace $HOME with the actual home directory */
+              path = g_strndup (path + 1, strlen (path) - 2);
+              const gchar *home_dir = g_get_home_dir ();
+
+              /* Replace $HOME */
+              gchar *temp = g_strdup_printf ("%s%s", home_dir, path + 5);
+              g_free (path);
+              path = temp;
+
+              /* Insert normalized key and path into the hash table */
+              g_hash_table_insert (user_dirs_map, g_strdup (key), path);
+
+              g_strfreev (full_name);
+              g_strfreev (split);
+            }
+        }
+      g_strfreev (lines);
+      g_free (contents);
+    }
+}
+
+/**
+ * get_user_dir_name:
+ * @dir_path : path of user dir.
+ *
+ * Returns : the name of dir.
+ */
+gchar *
+thunar_get_user_dir_name (const gchar *dir_path)
+{
+  /* Initilize the map */
+  if (user_dirs_map == NULL)
+    {
+      thunar_cache_user_dirs_paths ();
+    }
+
+  GList *keys = g_hash_table_get_keys (user_dirs_map);
+
+  for (GList *iter = keys; iter != NULL; iter = iter->next)
+    {
+      gchar *key = (gchar *) iter->data;
+      gchar *path = g_hash_table_lookup (user_dirs_map, key);
+
+      if (g_strcmp0 (dir_path, path) == 0)
+        {
+          g_list_free (keys);
+          return g_strdup (key);
+        }
+    }
+
+  g_list_free (keys);
+  return NULL;
+}
+
+
 
 GKeyFile *
 thunar_g_file_query_key_file (GFile        *file,
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index 3133d5614..f8f0a7bad 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -69,6 +69,12 @@ gboolean
 thunar_g_file_is_computer (GFile *file);
 gboolean
 thunar_g_file_is_network (GFile *file);
+void
+thunar_cache_user_dirs_paths ();
+gchar *
+thunar_get_user_dir_name (const gchar *dir_path);
+void
+thunar_user_dir_map_update (gchar *dir_name, gchar *new_path);
 
 GKeyFile *
 thunar_g_file_query_key_file (GFile        *file,
-- 
GitLab


From bae94449c3b79df99d10b51a3a9c2d10518a5279 Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Thu, 9 Jan 2025 19:42:09 +0530
Subject: [PATCH 04/17] Update: Cleanup variables

---
 thunar/thunar-file.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 5c9772528..76d2d9761 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -2021,6 +2021,8 @@ thunar_file_rename (ThunarFile   *file,
 
       g_object_unref (renamed_file);
       g_free (new_path);
+      g_free (dir_name);
+      g_free (old_path);
       return TRUE;
     }
   return FALSE;
-- 
GitLab


From 886bfea4ae003ee84edca3043689817c9be22dde Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Thu, 9 Jan 2025 20:22:27 +0530
Subject: [PATCH 05/17] Revert unwanted changes

---
 thunar/thunar-chooser-model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/thunar/thunar-chooser-model.c b/thunar/thunar-chooser-model.c
index 3fe13f103..b2cf063fd 100644
--- a/thunar/thunar-chooser-model.c
+++ b/thunar/thunar-chooser-model.c
@@ -420,7 +420,7 @@ thunar_chooser_model_remove (ThunarChooserModel *model,
                                              error);
 
   /* try to delete the file */
-  if (delete && succeed && g_app_info_delete (app_info))
+  if (delete &&succeed && g_app_info_delete (app_info))
     {
       g_set_error (error, G_IO_ERROR,
                    G_IO_ERROR_FAILED,
-- 
GitLab


From 236f1af9c6c3560c68a2c7d65c8e2ff81ff8aeb2 Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Thu, 9 Jan 2025 20:29:29 +0530
Subject: [PATCH 06/17] Revert unwanted changes

---
 thunar/thunar-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 76d2d9761..336474f51 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -505,7 +505,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-  /* verify that nobody's watching the file anymore */
+    /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
-- 
GitLab


From f7448ec063298e5531a0cc18007abc06e880545c Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Thu, 9 Jan 2025 23:36:55 +0530
Subject: [PATCH 07/17] Refactor thunar code

---
 thunar/thunar-file.c           | 14 +++++++-------
 thunar/thunar-gio-extensions.c | 35 +++++++++++++++++++---------------
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 336474f51..1ae085730 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -505,7 +505,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-    /* verify that nobody's watching the file anymore */
+  /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
@@ -1113,14 +1113,14 @@ thunar_file_info_reload (ThunarFile   *file,
   else
     file->collate_key_nocase = file->collate_key;
 
-  /* cleanup */
-  g_free (casefold);
-
   /* restore icon name if needed */
   if (file->icon_name == NULL)
     {
       thunar_file_get_icon_name (file, THUNAR_FILE_ICON_STATE_DEFAULT, gtk_icon_theme_get_default ());
     }
+
+  /* cleanup */
+  g_free (casefold);
 }
 
 
@@ -2007,7 +2007,7 @@ thunar_file_rename (ThunarFile   *file,
       new_path = g_file_get_path (thunar_file_get_file (file));
 
       /* update the config file */
-      snprintf (command, sizeof (command), "xdg-user-dirs-update --set %s %s", dir_name, new_path);
+      snprintf (command, sizeof (command), "xdg-user-dirs-update --set %s \"%s\"", dir_name, new_path);
       system (command);
 
       /* Update the path in our hashtable */
@@ -4141,10 +4141,10 @@ thunar_file_get_icon_name (ThunarFile         *file,
                 *special_names = "user-home";
               else
                 {
+                  /* ensure latest cache */
+                  g_reload_user_special_dirs_cache ();
                   for (i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
                     {
-                      /* ensure latest cache */
-                      g_reload_user_special_dirs_cache ();
                       special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
                       if (special_dir != NULL
                           && strcmp (path, special_dir) == 0)
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index fb3af80c7..2257a4d47 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -111,6 +111,7 @@ device_icon_name [] =
 /* clang-format on */
 
 
+static GHashTable *user_dirs_map = NULL;
 
 static const gchar *
 guess_device_type_from_icon_name (const gchar *icon_name);
@@ -351,8 +352,6 @@ thunar_g_file_is_network (GFile *file)
 }
 
 
-static GHashTable *user_dirs_map = NULL;
-
 /*
  * thunar_user_dir_map_update:
  * @dir_name: user dir name to change the path
@@ -364,22 +363,29 @@ thunar_user_dir_map_update (gchar *dir_name, gchar *new_path)
   g_hash_table_replace (user_dirs_map, dir_name, new_path);
 }
 
+static void
+thunar_user_dir_map_init (void)
+{
+  thunar_cache_user_dirs_paths ();
+}
+
 /* Cache the XDG directories with their names as keys and paths as values */
 void
 thunar_cache_user_dirs_paths (void)
 {
+  gchar *config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL);
+  gchar *contents = NULL;
+  gsize  length;
+
   if (user_dirs_map == NULL)
     {
       user_dirs_map = g_hash_table_new (g_str_hash, g_str_equal);
     }
 
-  gchar *config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL);
-  gchar *contents = NULL;
-  gsize  length;
-
   if (g_file_get_contents (config_file, &contents, &length, NULL))
     {
       gchar **lines = g_strsplit (contents, "\n", -1);
+
       for (int i = 0; lines[i] != NULL; i++)
         {
           if (g_str_has_prefix (lines[i], "XDG_"))
@@ -390,16 +396,20 @@ thunar_cache_user_dirs_paths (void)
               /* split xdg-dir by _ */
               gchar **full_name = g_strsplit (split[0], "_", 3);
 
-              /* get the name */
+              /* get the name an path*/
               gchar *key = g_strdup (full_name[1]);
               gchar *path = g_strdup (split[1]);
 
+              const gchar *home_dir = g_get_home_dir ();
+
+              gchar *temp;
+
               /* Remove quotes and replace $HOME with the actual home directory */
               path = g_strndup (path + 1, strlen (path) - 2);
-              const gchar *home_dir = g_get_home_dir ();
 
               /* Replace $HOME */
-              gchar *temp = g_strdup_printf ("%s%s", home_dir, path + 5);
+              temp = g_strdup_printf ("%s%s", home_dir, path + 5);
+
               g_free (path);
               path = temp;
 
@@ -424,12 +434,7 @@ thunar_cache_user_dirs_paths (void)
 gchar *
 thunar_get_user_dir_name (const gchar *dir_path)
 {
-  /* Initilize the map */
-  if (user_dirs_map == NULL)
-    {
-      thunar_cache_user_dirs_paths ();
-    }
-
+  thunar_user_dir_map_init ();
   GList *keys = g_hash_table_get_keys (user_dirs_map);
 
   for (GList *iter = keys; iter != NULL; iter = iter->next)
-- 
GitLab


From 9b0e75443ee3e0058cab5878d276dfcf0cb81879 Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Thu, 9 Jan 2025 23:44:22 +0530
Subject: [PATCH 08/17] Add spaces before comment

---
 thunar/thunar-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 1ae085730..8f033e9d5 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -505,7 +505,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-  /* verify that nobody's watching the file anymore */
+    /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
-- 
GitLab


From 36b5459434f08d6dbe69f47e19b1035df3d699a4 Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Sat, 11 Jan 2025 11:38:21 +0530
Subject: [PATCH 09/17] Update: Check before updating config and remove local
 cache

---
 thunar/thunar-file.c           |  92 +++++++++++++++++++++++++----
 thunar/thunar-gio-extensions.c | 104 ---------------------------------
 thunar/thunar-gio-extensions.h |   7 ---
 3 files changed, 80 insertions(+), 123 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 8f033e9d5..bd0174f13 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -505,7 +505,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-    /* verify that nobody's watching the file anymore */
+  /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
@@ -1950,7 +1950,84 @@ thunar_file_launch (ThunarFile  *file,
   return succeed;
 }
 
+static gboolean
+thunar_g_is_user_special_dir (const gchar *path)
+{
+  g_return_val_if_fail (path != NULL, FALSE);
+  const gchar *special_dir;
+
+  /* ensure latest cache */
+  g_reload_user_special_dirs_cache ();
+
+  /* check all special directories */
+  for (guint i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
+    {
+      special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
+      if (special_dir != NULL && strcmp (path, special_dir) == 0)
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+thunar_g_update_user_special_dir (const gchar *old_path, const gchar *new_path)
+{
+  g_return_if_fail (old_path != NULL);
+  g_return_if_fail (new_path != NULL);
+  const gchar *special_dir;
+  gchar       *command;
 
+  /* ensure latest cache */
+  g_reload_user_special_dirs_cache ();
+
+  for (guint i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
+    {
+      special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
+      if (special_dir != NULL && strcmp (old_path, special_dir) == 0)
+        {
+          /* map the GUserDirectory type to XDG name */
+          const gchar *xdg_name;
+          switch (thunar_file_dirs[i].type)
+            {
+            case G_USER_DIRECTORY_DESKTOP:
+              xdg_name = "DESKTOP";
+              break;
+            case G_USER_DIRECTORY_DOCUMENTS:
+              xdg_name = "DOCUMENTS";
+              break;
+            case G_USER_DIRECTORY_DOWNLOAD:
+              xdg_name = "DOWNLOAD";
+              break;
+            case G_USER_DIRECTORY_MUSIC:
+              xdg_name = "MUSIC";
+              break;
+            case G_USER_DIRECTORY_PICTURES:
+              xdg_name = "PICTURES";
+              break;
+            case G_USER_DIRECTORY_PUBLIC_SHARE:
+              xdg_name = "PUBLICSHARE";
+              break;
+            case G_USER_DIRECTORY_TEMPLATES:
+              xdg_name = "TEMPLATES";
+              break;
+            case G_USER_DIRECTORY_VIDEOS:
+              xdg_name = "VIDEOS";
+              break;
+            default:
+              continue;
+            }
+
+          command = g_strdup_printf ("xdg-user-dirs-update --set %s \"%s\"",
+                                     xdg_name, new_path);
+          if (g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL))
+            g_reload_user_special_dirs_cache ();
+
+          g_free (command);
+          break;
+        }
+    }
+}
 
 /**
  * thunar_file_rename:
@@ -1991,12 +2068,8 @@ thunar_file_rename (ThunarFile   *file,
     {
       gchar *new_path;
       gchar *old_path;
-      gchar *dir_name;
-      char   command[256];
-
 
       old_path = g_file_get_path (thunar_file_get_file (file));
-      dir_name = thunar_get_user_dir_name (old_path);
 
       /* replace GFile in ThunarFile for the renamed file */
       thunar_file_replace_file (file, renamed_file);
@@ -2006,12 +2079,8 @@ thunar_file_rename (ThunarFile   *file,
 
       new_path = g_file_get_path (thunar_file_get_file (file));
 
-      /* update the config file */
-      snprintf (command, sizeof (command), "xdg-user-dirs-update --set %s \"%s\"", dir_name, new_path);
-      system (command);
-
-      /* Update the path in our hashtable */
-      thunar_user_dir_map_update (g_strdup (dir_name), g_strdup (new_path));
+      if (thunar_g_is_user_special_dir (old_path))
+        thunar_g_update_user_special_dir (old_path, new_path);
 
       if (!called_from_job)
         {
@@ -2021,7 +2090,6 @@ thunar_file_rename (ThunarFile   *file,
 
       g_object_unref (renamed_file);
       g_free (new_path);
-      g_free (dir_name);
       g_free (old_path);
       return TRUE;
     }
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index 2257a4d47..9f370c383 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -111,8 +111,6 @@ device_icon_name [] =
 /* clang-format on */
 
 
-static GHashTable *user_dirs_map = NULL;
-
 static const gchar *
 guess_device_type_from_icon_name (const gchar *icon_name);
 static GFileInfo *
@@ -352,108 +350,6 @@ thunar_g_file_is_network (GFile *file)
 }
 
 
-/*
- * thunar_user_dir_map_update:
- * @dir_name: user dir name to change the path
- * @new_path: new path of user_dir
- */
-void
-thunar_user_dir_map_update (gchar *dir_name, gchar *new_path)
-{
-  g_hash_table_replace (user_dirs_map, dir_name, new_path);
-}
-
-static void
-thunar_user_dir_map_init (void)
-{
-  thunar_cache_user_dirs_paths ();
-}
-
-/* Cache the XDG directories with their names as keys and paths as values */
-void
-thunar_cache_user_dirs_paths (void)
-{
-  gchar *config_file = g_build_filename (g_get_user_config_dir (), "user-dirs.dirs", NULL);
-  gchar *contents = NULL;
-  gsize  length;
-
-  if (user_dirs_map == NULL)
-    {
-      user_dirs_map = g_hash_table_new (g_str_hash, g_str_equal);
-    }
-
-  if (g_file_get_contents (config_file, &contents, &length, NULL))
-    {
-      gchar **lines = g_strsplit (contents, "\n", -1);
-
-      for (int i = 0; lines[i] != NULL; i++)
-        {
-          if (g_str_has_prefix (lines[i], "XDG_"))
-            {
-              /* split xdg-dir and path */
-              gchar **split = g_strsplit (lines[i], "=", 2);
-
-              /* split xdg-dir by _ */
-              gchar **full_name = g_strsplit (split[0], "_", 3);
-
-              /* get the name an path*/
-              gchar *key = g_strdup (full_name[1]);
-              gchar *path = g_strdup (split[1]);
-
-              const gchar *home_dir = g_get_home_dir ();
-
-              gchar *temp;
-
-              /* Remove quotes and replace $HOME with the actual home directory */
-              path = g_strndup (path + 1, strlen (path) - 2);
-
-              /* Replace $HOME */
-              temp = g_strdup_printf ("%s%s", home_dir, path + 5);
-
-              g_free (path);
-              path = temp;
-
-              /* Insert normalized key and path into the hash table */
-              g_hash_table_insert (user_dirs_map, g_strdup (key), path);
-
-              g_strfreev (full_name);
-              g_strfreev (split);
-            }
-        }
-      g_strfreev (lines);
-      g_free (contents);
-    }
-}
-
-/**
- * get_user_dir_name:
- * @dir_path : path of user dir.
- *
- * Returns : the name of dir.
- */
-gchar *
-thunar_get_user_dir_name (const gchar *dir_path)
-{
-  thunar_user_dir_map_init ();
-  GList *keys = g_hash_table_get_keys (user_dirs_map);
-
-  for (GList *iter = keys; iter != NULL; iter = iter->next)
-    {
-      gchar *key = (gchar *) iter->data;
-      gchar *path = g_hash_table_lookup (user_dirs_map, key);
-
-      if (g_strcmp0 (dir_path, path) == 0)
-        {
-          g_list_free (keys);
-          return g_strdup (key);
-        }
-    }
-
-  g_list_free (keys);
-  return NULL;
-}
-
-
 
 GKeyFile *
 thunar_g_file_query_key_file (GFile        *file,
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index f8f0a7bad..3e952e9f4 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -69,13 +69,6 @@ gboolean
 thunar_g_file_is_computer (GFile *file);
 gboolean
 thunar_g_file_is_network (GFile *file);
-void
-thunar_cache_user_dirs_paths ();
-gchar *
-thunar_get_user_dir_name (const gchar *dir_path);
-void
-thunar_user_dir_map_update (gchar *dir_name, gchar *new_path);
-
 GKeyFile *
 thunar_g_file_query_key_file (GFile        *file,
                               GCancellable *cancellable,
-- 
GitLab


From 5c3ff8f81144c7b0ca75f5fab2992840c37952ef Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Sat, 11 Jan 2025 11:47:05 +0530
Subject: [PATCH 10/17] Fix formatting

---
 thunar/thunar-file.c           | 3 ++-
 thunar/thunar-gio-extensions.c | 1 +
 thunar/thunar-gio-extensions.h | 1 +
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index bd0174f13..bf021f9f1 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -505,7 +505,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-  /* verify that nobody's watching the file anymore */
+    /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
@@ -2093,6 +2093,7 @@ thunar_file_rename (ThunarFile   *file,
       g_free (old_path);
       return TRUE;
     }
+
   return FALSE;
 }
 
diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c
index 9f370c383..c208f1d8f 100644
--- a/thunar/thunar-gio-extensions.c
+++ b/thunar/thunar-gio-extensions.c
@@ -111,6 +111,7 @@ device_icon_name [] =
 /* clang-format on */
 
 
+
 static const gchar *
 guess_device_type_from_icon_name (const gchar *icon_name);
 static GFileInfo *
diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h
index 3e952e9f4..3133d5614 100644
--- a/thunar/thunar-gio-extensions.h
+++ b/thunar/thunar-gio-extensions.h
@@ -69,6 +69,7 @@ gboolean
 thunar_g_file_is_computer (GFile *file);
 gboolean
 thunar_g_file_is_network (GFile *file);
+
 GKeyFile *
 thunar_g_file_query_key_file (GFile        *file,
                               GCancellable *cancellable,
-- 
GitLab


From cac84ccf2ab11b68f4e99e1e7bc27176c374994f Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Sat, 11 Jan 2025 12:48:31 +0530
Subject: [PATCH 11/17] Update: removed checks for each file while update

---
 thunar/thunar-file.c | 123 ++++++++++++++++++++++++-------------------
 1 file changed, 68 insertions(+), 55 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index bf021f9f1..9ebe2a725 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -1950,10 +1950,20 @@ thunar_file_launch (ThunarFile  *file,
   return succeed;
 }
 
-static gboolean
-thunar_g_is_user_special_dir (const gchar *path)
+
+/**
+ * thunar_g_get_user_special_dir_type:
+ * @path: a file path to check.
+ *
+ * Returns the #GUserDirectory type for the given @path if it matches a known
+ * user-special directory (e.g., Desktop, Documents). If no match is found,
+ * returns %G_USER_N_DIRECTORIES.
+ */
+
+static GUserDirectory
+thunar_g_get_user_special_dir_type (const gchar *path)
 {
-  g_return_val_if_fail (path != NULL, FALSE);
+  g_return_val_if_fail (path != NULL, G_USER_N_DIRECTORIES);
   const gchar *special_dir;
 
   /* ensure latest cache */
@@ -1964,69 +1974,71 @@ thunar_g_is_user_special_dir (const gchar *path)
     {
       special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
       if (special_dir != NULL && strcmp (path, special_dir) == 0)
-        return TRUE;
+        return thunar_file_dirs[i].type;
     }
 
-  return FALSE;
+  return G_USER_N_DIRECTORIES;
 }
 
+
+/**
+ * thunar_g_update_user_special_dir:
+ * @old_path: the current path of the special directory.
+ * @new_path: the new path to set.
+ * @dir_type: the #GUserDirectory type.
+ *
+ * Updates the user-special directory of @dir_type to @new_path and reloads
+ * the cache.
+ */
 static void
-thunar_g_update_user_special_dir (const gchar *old_path, const gchar *new_path)
+thunar_g_update_user_special_dir (const gchar   *old_path,
+                                  const gchar   *new_path,
+                                  GUserDirectory dir_type)
 {
   g_return_if_fail (old_path != NULL);
   g_return_if_fail (new_path != NULL);
-  const gchar *special_dir;
-  gchar       *command;
+  g_return_if_fail (dir_type < G_USER_N_DIRECTORIES);
 
-  /* ensure latest cache */
-  g_reload_user_special_dirs_cache ();
+  const gchar *xdg_name;
+  gchar       *command;
 
-  for (guint i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
+  /* map the GUserDirectory type to XDG name */
+  switch (dir_type)
     {
-      special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
-      if (special_dir != NULL && strcmp (old_path, special_dir) == 0)
-        {
-          /* map the GUserDirectory type to XDG name */
-          const gchar *xdg_name;
-          switch (thunar_file_dirs[i].type)
-            {
-            case G_USER_DIRECTORY_DESKTOP:
-              xdg_name = "DESKTOP";
-              break;
-            case G_USER_DIRECTORY_DOCUMENTS:
-              xdg_name = "DOCUMENTS";
-              break;
-            case G_USER_DIRECTORY_DOWNLOAD:
-              xdg_name = "DOWNLOAD";
-              break;
-            case G_USER_DIRECTORY_MUSIC:
-              xdg_name = "MUSIC";
-              break;
-            case G_USER_DIRECTORY_PICTURES:
-              xdg_name = "PICTURES";
-              break;
-            case G_USER_DIRECTORY_PUBLIC_SHARE:
-              xdg_name = "PUBLICSHARE";
-              break;
-            case G_USER_DIRECTORY_TEMPLATES:
-              xdg_name = "TEMPLATES";
-              break;
-            case G_USER_DIRECTORY_VIDEOS:
-              xdg_name = "VIDEOS";
-              break;
-            default:
-              continue;
-            }
+    case G_USER_DIRECTORY_DESKTOP:
+      xdg_name = "DESKTOP";
+      break;
+    case G_USER_DIRECTORY_DOCUMENTS:
+      xdg_name = "DOCUMENTS";
+      break;
+    case G_USER_DIRECTORY_DOWNLOAD:
+      xdg_name = "DOWNLOAD";
+      break;
+    case G_USER_DIRECTORY_MUSIC:
+      xdg_name = "MUSIC";
+      break;
+    case G_USER_DIRECTORY_PICTURES:
+      xdg_name = "PICTURES";
+      break;
+    case G_USER_DIRECTORY_PUBLIC_SHARE:
+      xdg_name = "PUBLICSHARE";
+      break;
+    case G_USER_DIRECTORY_TEMPLATES:
+      xdg_name = "TEMPLATES";
+      break;
+    case G_USER_DIRECTORY_VIDEOS:
+      xdg_name = "VIDEOS";
+      break;
+    default:
+      return;
+    }
 
-          command = g_strdup_printf ("xdg-user-dirs-update --set %s \"%s\"",
-                                     xdg_name, new_path);
-          if (g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL))
-            g_reload_user_special_dirs_cache ();
+  command = g_strdup_printf ("xdg-user-dirs-update --set %s \"%s\"",
+                             xdg_name, new_path);
+  if (g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL))
+    g_reload_user_special_dirs_cache ();
 
-          g_free (command);
-          break;
-        }
-    }
+  g_free (command);
 }
 
 /**
@@ -2079,8 +2091,9 @@ thunar_file_rename (ThunarFile   *file,
 
       new_path = g_file_get_path (thunar_file_get_file (file));
 
-      if (thunar_g_is_user_special_dir (old_path))
-        thunar_g_update_user_special_dir (old_path, new_path);
+      GUserDirectory dir_type = thunar_g_get_user_special_dir_type (old_path);
+      if (dir_type != G_USER_N_DIRECTORIES)
+        thunar_g_update_user_special_dir (old_path, new_path, dir_type);
 
       if (!called_from_job)
         {
-- 
GitLab


From 19fd09da9002cdba808b5b918abc547b32b1788e Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Mon, 13 Jan 2025 21:15:44 +0530
Subject: [PATCH 12/17] Update: - Add xdg_name to thunar_file_dirs - Remove
 redundant cache reload - Add NULL check for new_path - Simplify
 thunar_g_update_user_special_dir by removing redundant param

---
 thunar/thunar-file.c | 97 ++++++++++++++------------------------------
 1 file changed, 31 insertions(+), 66 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 9ebe2a725..6f794935a 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -257,15 +257,16 @@ static struct
 {
   GUserDirectory type;
   const gchar   *icon_name;
+  const gchar   *xdg_name;
 } thunar_file_dirs[] = {
-  { G_USER_DIRECTORY_DESKTOP, "user-desktop" },
-  { G_USER_DIRECTORY_DOCUMENTS, "folder-documents" },
-  { G_USER_DIRECTORY_DOWNLOAD, "folder-download" },
-  { G_USER_DIRECTORY_MUSIC, "folder-music" },
-  { G_USER_DIRECTORY_PICTURES, "folder-pictures" },
-  { G_USER_DIRECTORY_PUBLIC_SHARE, "folder-publicshare" },
-  { G_USER_DIRECTORY_TEMPLATES, "folder-templates" },
-  { G_USER_DIRECTORY_VIDEOS, "folder-videos" }
+  { G_USER_DIRECTORY_DESKTOP, "user-desktop", "DESKTOP" },
+  { G_USER_DIRECTORY_DOCUMENTS, "folder-documents", "DOCUMENTS" },
+  { G_USER_DIRECTORY_DOWNLOAD, "folder-download", "DOWNLOAD" },
+  { G_USER_DIRECTORY_MUSIC, "folder-music", "MUSIC" },
+  { G_USER_DIRECTORY_PICTURES, "folder-pictures", "PICTURES" },
+  { G_USER_DIRECTORY_PUBLIC_SHARE, "folder-publicshare", "PUBLICSHARE" },
+  { G_USER_DIRECTORY_TEMPLATES, "folder-templates", "TEMPLATES" },
+  { G_USER_DIRECTORY_VIDEOS, "folder-videos", "VIDEOS" }
 };
 
 
@@ -505,7 +506,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-    /* verify that nobody's watching the file anymore */
+  /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
@@ -1955,29 +1956,26 @@ thunar_file_launch (ThunarFile  *file,
  * thunar_g_get_user_special_dir_type:
  * @path: a file path to check.
  *
- * Returns the #GUserDirectory type for the given @path if it matches a known
+ * Returns the xdg_name for the given @path if it matches a known
  * user-special directory (e.g., Desktop, Documents). If no match is found,
- * returns %G_USER_N_DIRECTORIES.
+ * returns NULL.
  */
 
-static GUserDirectory
+static const gchar *
 thunar_g_get_user_special_dir_type (const gchar *path)
 {
-  g_return_val_if_fail (path != NULL, G_USER_N_DIRECTORIES);
+  g_return_val_if_fail (path != NULL, NULL);
   const gchar *special_dir;
 
-  /* ensure latest cache */
-  g_reload_user_special_dirs_cache ();
-
   /* check all special directories */
   for (guint i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
     {
       special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
       if (special_dir != NULL && strcmp (path, special_dir) == 0)
-        return thunar_file_dirs[i].type;
+        return thunar_file_dirs[i].xdg_name;
     }
 
-  return G_USER_N_DIRECTORIES;
+  return NULL;
 }
 
 
@@ -1991,51 +1989,17 @@ thunar_g_get_user_special_dir_type (const gchar *path)
  * the cache.
  */
 static void
-thunar_g_update_user_special_dir (const gchar   *old_path,
-                                  const gchar   *new_path,
-                                  GUserDirectory dir_type)
+thunar_g_update_user_special_dir (const gchar *new_path,
+                                  const gchar *xdg_name)
 {
-  g_return_if_fail (old_path != NULL);
   g_return_if_fail (new_path != NULL);
-  g_return_if_fail (dir_type < G_USER_N_DIRECTORIES);
 
-  const gchar *xdg_name;
-  gchar       *command;
-
-  /* map the GUserDirectory type to XDG name */
-  switch (dir_type)
-    {
-    case G_USER_DIRECTORY_DESKTOP:
-      xdg_name = "DESKTOP";
-      break;
-    case G_USER_DIRECTORY_DOCUMENTS:
-      xdg_name = "DOCUMENTS";
-      break;
-    case G_USER_DIRECTORY_DOWNLOAD:
-      xdg_name = "DOWNLOAD";
-      break;
-    case G_USER_DIRECTORY_MUSIC:
-      xdg_name = "MUSIC";
-      break;
-    case G_USER_DIRECTORY_PICTURES:
-      xdg_name = "PICTURES";
-      break;
-    case G_USER_DIRECTORY_PUBLIC_SHARE:
-      xdg_name = "PUBLICSHARE";
-      break;
-    case G_USER_DIRECTORY_TEMPLATES:
-      xdg_name = "TEMPLATES";
-      break;
-    case G_USER_DIRECTORY_VIDEOS:
-      xdg_name = "VIDEOS";
-      break;
-    default:
-      return;
-    }
+  gchar *command;
 
   command = g_strdup_printf ("xdg-user-dirs-update --set %s \"%s\"",
                              xdg_name, new_path);
   if (g_spawn_command_line_sync (command, NULL, NULL, NULL, NULL))
+    /* reload the cache to reflect changes */
     g_reload_user_special_dirs_cache ();
 
   g_free (command);
@@ -2091,18 +2055,21 @@ thunar_file_rename (ThunarFile   *file,
 
       new_path = g_file_get_path (thunar_file_get_file (file));
 
-      GUserDirectory dir_type = thunar_g_get_user_special_dir_type (old_path);
-      if (dir_type != G_USER_N_DIRECTORIES)
-        thunar_g_update_user_special_dir (old_path, new_path, dir_type);
-
-      if (!called_from_job)
+      if (new_path != NULL)
         {
-          /* emit the file changed signal */
-          thunar_file_changed (file);
+          const gchar *xdg_name = thunar_g_get_user_special_dir_type (old_path);
+          if (xdg_name != NULL)
+            thunar_g_update_user_special_dir (new_path, xdg_name);
+
+          if (!called_from_job)
+            {
+              /* emit the file changed signal */
+              thunar_file_changed (file);
+            }
+          g_free (new_path);
         }
 
       g_object_unref (renamed_file);
-      g_free (new_path);
       g_free (old_path);
       return TRUE;
     }
@@ -4223,8 +4190,6 @@ thunar_file_get_icon_name (ThunarFile         *file,
                 *special_names = "user-home";
               else
                 {
-                  /* ensure latest cache */
-                  g_reload_user_special_dirs_cache ();
                   for (i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
                     {
                       special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
-- 
GitLab


From 6456d23816fccd4ed284044177265117b89b93fb Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Mon, 13 Jan 2025 21:22:03 +0530
Subject: [PATCH 13/17] Remove irrelevant comment

---
 thunar/thunar-file.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 6f794935a..d11a45d51 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -1981,7 +1981,6 @@ thunar_g_get_user_special_dir_type (const gchar *path)
 
 /**
  * thunar_g_update_user_special_dir:
- * @old_path: the current path of the special directory.
  * @new_path: the new path to set.
  * @dir_type: the #GUserDirectory type.
  *
-- 
GitLab


From 3be6bfb1399a7d4184e2b326a1343f257beaa9a0 Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Mon, 13 Jan 2025 21:31:34 +0530
Subject: [PATCH 14/17] Fix formatting

---
 thunar/thunar-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index d11a45d51..907aa15bc 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -506,7 +506,7 @@ thunar_file_finalize (GObject *object)
   if (file->signal_changed_source_id != 0)
     g_source_remove (file->signal_changed_source_id);
 
-  /* verify that nobody's watching the file anymore */
+    /* verify that nobody's watching the file anymore */
 #ifdef G_ENABLE_DEBUG
   ThunarFileWatch *file_watch = g_object_get_qdata (G_OBJECT (file), thunar_file_watch_quark);
   if (file_watch != NULL)
-- 
GitLab


From 45a950adcf4e6ff6a31473def9ed2efe9e348da5 Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Mon, 13 Jan 2025 22:07:41 +0530
Subject: [PATCH 15/17] Revert emit signal code

---
 thunar/thunar-file.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 907aa15bc..20b49a068 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -2059,15 +2059,15 @@ thunar_file_rename (ThunarFile   *file,
           const gchar *xdg_name = thunar_g_get_user_special_dir_type (old_path);
           if (xdg_name != NULL)
             thunar_g_update_user_special_dir (new_path, xdg_name);
-
-          if (!called_from_job)
-            {
-              /* emit the file changed signal */
-              thunar_file_changed (file);
-            }
           g_free (new_path);
         }
 
+      if (!called_from_job)
+        {
+          /* emit the file changed signal */
+          thunar_file_changed (file);
+        }
+
       g_object_unref (renamed_file);
       g_free (old_path);
       return TRUE;
-- 
GitLab


From 6f7c32fbb5aa1e59a8196a75fa3c0d1c0a3a6533 Mon Sep 17 00:00:00 2001
From: Rishabh Singh <rishabh0739@gmail.com>
Date: Thu, 16 Jan 2025 04:02:27 +0000
Subject: [PATCH 16/17] Use g_strcmp0 instead of strcmp Check old_path for NULL
 Refactor comments Co-authored-by: @alexxcons

---
 thunar/thunar-file.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index 20b49a068..e94f3afd2 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -1960,7 +1960,6 @@ thunar_file_launch (ThunarFile  *file,
  * user-special directory (e.g., Desktop, Documents). If no match is found,
  * returns NULL.
  */
-
 static const gchar *
 thunar_g_get_user_special_dir_type (const gchar *path)
 {
@@ -1971,7 +1970,7 @@ thunar_g_get_user_special_dir_type (const gchar *path)
   for (guint i = 0; i < G_N_ELEMENTS (thunar_file_dirs); i++)
     {
       special_dir = g_get_user_special_dir (thunar_file_dirs[i].type);
-      if (special_dir != NULL && strcmp (path, special_dir) == 0)
+      if (special_dir != NULL && g_strcmp0 (path, special_dir) == 0)
         return thunar_file_dirs[i].xdg_name;
     }
 
@@ -1982,7 +1981,7 @@ thunar_g_get_user_special_dir_type (const gchar *path)
 /**
  * thunar_g_update_user_special_dir:
  * @new_path: the new path to set.
- * @dir_type: the #GUserDirectory type.
+ * @xdg_name: the XDG name of the directory
  *
  * Updates the user-special directory of @dir_type to @new_path and reloads
  * the cache.
@@ -2054,12 +2053,11 @@ thunar_file_rename (ThunarFile   *file,
 
       new_path = g_file_get_path (thunar_file_get_file (file));
 
-      if (new_path != NULL)
+      if (new_path != NULL && old_path != NULL)
         {
           const gchar *xdg_name = thunar_g_get_user_special_dir_type (old_path);
           if (xdg_name != NULL)
             thunar_g_update_user_special_dir (new_path, xdg_name);
-          g_free (new_path);
         }
 
       if (!called_from_job)
@@ -2069,6 +2067,7 @@ thunar_file_rename (ThunarFile   *file,
         }
 
       g_object_unref (renamed_file);
+      g_free (new_path);
       g_free (old_path);
       return TRUE;
     }
-- 
GitLab


From e8f3fad057b9d76d352d0431332c8d111e63a03b Mon Sep 17 00:00:00 2001
From: Rishabh705 <rishabh0739@gmail.com>
Date: Thu, 16 Jan 2025 09:47:07 +0530
Subject: [PATCH 17/17] Remove uneccessary call for thunar_get_icon_name

---
 thunar/thunar-file.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c
index e94f3afd2..9f05bf39d 100644
--- a/thunar/thunar-file.c
+++ b/thunar/thunar-file.c
@@ -1114,12 +1114,6 @@ thunar_file_info_reload (ThunarFile   *file,
   else
     file->collate_key_nocase = file->collate_key;
 
-  /* restore icon name if needed */
-  if (file->icon_name == NULL)
-    {
-      thunar_file_get_icon_name (file, THUNAR_FILE_ICON_STATE_DEFAULT, gtk_icon_theme_get_default ());
-    }
-
   /* cleanup */
   g_free (casefold);
 }
-- 
GitLab