[nautilus/wip/antoniof/deep-size-hidden-files] directory-async: Count hidden files on deep size



commit 840b089903787b36b0004be251247282ca28eac3
Author: António Fernandes <antoniof gnome org>
Date:   Sun Apr 19 11:23:28 2020 +0100

    directory-async: Count hidden files on deep size
    
    We always skip hidden and backup files when counting the number of
    files in a directory, if "show-hidden-files" is turned Off. This is
    done so that the item count matches which items the user sees.
    
    However, we have been skipping them also when computing the total size
    of a folder contents. This is wrong because hiding content doesn't
    make the folder actually smaller in size.
    
    So, let's decouple deep size from deep count, such that, even when
    skipping files in deep count, their size is always added to the total
    content size.
    
    Closes https://gitlab.gnome.org/GNOME/nautilus/-/issues/638

 src/nautilus-directory-async.c | 47 +++++++++++++++++++++++++++++++-----------
 1 file changed, 35 insertions(+), 12 deletions(-)
---
diff --git a/src/nautilus-directory-async.c b/src/nautilus-directory-async.c
index d5b93b5ac..e9fe732e3 100644
--- a/src/nautilus-directory-async.c
+++ b/src/nautilus-directory-async.c
@@ -114,7 +114,9 @@ struct DeepCountState
     GCancellable *cancellable;
     GFileEnumerator *enumerator;
     GFile *deep_count_location;
+    gboolean deep_size_only;
     GList *deep_count_subdirectories;
+    GList *deep_size_only_subdirectories;
     GArray *seen_deep_count_inodes;
     char *fs_id;
 };
@@ -2808,45 +2810,54 @@ deep_count_one (DeepCountState *state,
                 GFileInfo      *info)
 {
     NautilusFile *file;
-    GFile *subdir;
     gboolean is_seen_inode;
-    const char *fs_id;
-
-    if (should_skip_file (NULL, info))
-    {
-        return;
-    }
+    gboolean skip_count;
 
     is_seen_inode = seen_inode (state, info);
     if (!is_seen_inode)
     {
         mark_inode_as_seen (state, info);
     }
+    /* Count item only if not skipped (because it's not user-visible) */
+    skip_count = should_skip_file (NULL, info) || state->deep_size_only;
 
     file = state->directory->details->deep_count_file;
 
     if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)
     {
+        const char *fs_id;
+
         /* Count the directory. */
-        file->details->deep_directory_count += 1;
+        file->details->deep_directory_count += skip_count ? 0 : 1;
 
         /* Record the fact that we have to descend into this directory. */
         fs_id = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_ID_FILESYSTEM);
         if (g_strcmp0 (fs_id, state->fs_id) == 0)
         {
+            GFile *subdir;
+
             /* only if it is on the same filesystem */
             subdir = g_file_get_child (state->deep_count_location, g_file_info_get_name (info));
-            state->deep_count_subdirectories = g_list_prepend
-                                                   (state->deep_count_subdirectories, subdir);
+            if (skip_count)
+            {
+                /* Count the size, even if skipped (because it still takes space). */
+                state->deep_size_only_subdirectories = g_list_prepend
+                                                           (state->deep_size_only_subdirectories, subdir);
+            }
+            else
+            {
+                state->deep_count_subdirectories = g_list_prepend
+                                                       (state->deep_count_subdirectories, subdir);
+            }
         }
     }
     else
     {
         /* Even non-regular files count as files. */
-        file->details->deep_file_count += 1;
+        file->details->deep_file_count += skip_count ? 0 : 1;
     }
 
-    /* Count the size. */
+    /* Count the size, even if skipped (because it still takes space). */
     if (!is_seen_inode && g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE))
     {
         file->details->deep_size += g_file_info_get_size (info);
@@ -2871,6 +2882,7 @@ deep_count_state_free (DeepCountState *state)
         g_object_unref (state->deep_count_location);
     }
     g_list_free_full (state->deep_count_subdirectories, g_object_unref);
+    g_list_free_full (state->deep_size_only_subdirectories, g_object_unref);
     g_array_free (state->seen_deep_count_inodes, TRUE);
     g_free (state->fs_id);
     g_free (state);
@@ -2898,6 +2910,16 @@ deep_count_next_dir (DeepCountState *state)
         location = state->deep_count_subdirectories->data;
         state->deep_count_subdirectories = g_list_remove
                                                (state->deep_count_subdirectories, location);
+        state->deep_size_only = FALSE;
+        deep_count_load (state, location);
+        g_object_unref (location);
+    }
+    else if (state->deep_size_only_subdirectories != NULL)
+    {
+        location = state->deep_size_only_subdirectories->data;
+        state->deep_size_only_subdirectories = g_list_remove
+                                                   (state->deep_size_only_subdirectories, location);
+        state->deep_size_only = TRUE;
         deep_count_load (state, location);
         g_object_unref (location);
     }
@@ -3131,6 +3153,7 @@ deep_count_start (NautilusDirectory *directory,
     state = g_new0 (DeepCountState, 1);
     state->directory = directory;
     state->cancellable = g_cancellable_new ();
+    state->deep_size_only = FALSE;
     state->seen_deep_count_inodes = g_array_new (FALSE, TRUE, sizeof (guint64));
     state->fs_id = NULL;
 


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