[gnome-software/gnome-41: 1/2] gs_utils_get_file_size: Do not follow symlinks




commit 1c6a0a5dc4dd214928869c564cc7260c7c9e842b
Author: Milan Crha <mcrha redhat com>
Date:   Fri Nov 5 11:11:04 2021 +0100

    gs_utils_get_file_size: Do not follow symlinks
    
    The symlinks can point to a shared storage, or even out of the directory,
    whose size is being calculated, thus skip them, to have more accurate
    information about the directory size.
    
    Closes https://gitlab.gnome.org/GNOME/gnome-software/-/issues/1528

 lib/gs-utils.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/lib/gs-utils.c b/lib/gs-utils.c
index 86377e295..d549e2acd 100644
--- a/lib/gs-utils.c
+++ b/lib/gs-utils.c
@@ -1490,12 +1490,14 @@ gs_utils_get_file_size (const gchar *filename,
 
                                        if (g_stat (full_path, &st) == 0 && (include_func == NULL ||
                                            include_func (full_path + base_len,
-                                                         S_ISLNK (st.st_mode) ? G_FILE_TEST_IS_SYMLINK :
+                                                         g_file_test (full_path, G_FILE_TEST_IS_SYMLINK) ? 
G_FILE_TEST_IS_SYMLINK :
                                                          S_ISDIR (st.st_mode) ? G_FILE_TEST_IS_DIR :
                                                          G_FILE_TEST_IS_REGULAR,
                                                          user_data))) {
                                                if (S_ISDIR (st.st_mode)) {
-                                                       dirs_to_do = g_slist_prepend (dirs_to_do, 
g_steal_pointer (&full_path));
+                                                       /* Skip symlinks, they can point to a shared storage 
*/
+                                                       if (!g_file_test (full_path, G_FILE_TEST_IS_SYMLINK))
+                                                               dirs_to_do = g_slist_prepend (dirs_to_do, 
g_steal_pointer (&full_path));
                                                } else {
                                                        size += st.st_size;
                                                }


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