diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 009d2897d00e5adda0d82a49b16d5002e58324bf..e509a080c98a8c7ca2df8bd568d267df7c26637e 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -2833,6 +2833,53 @@ thunar_file_is_directory (const ThunarFile *file) +/** + * thunar_g_file_is_empty_directory: + * @file : a #ThunarFile instance. + * + * Checks whether @file refers to an empty directory + * If the directory is not readable, the method will as well return TRUE + * + * Return value: %TRUE if @file is an empty directory. + **/ +gboolean +thunar_file_is_empty_directory (const ThunarFile *file) +{ + GFileEnumerator *enumerator; + GError *err = NULL; + gboolean is_empty = TRUE; + GFileInfo *info; + + _thunar_return_val_if_fail (THUNAR_IS_FILE (file), FALSE); + + if (thunar_file_is_directory (file) == FALSE) + return FALSE; + + /* Threat non-readable direcories like they were empty */ + if (!thunar_file_is_readable (file)) + return TRUE; + + enumerator = g_file_enumerate_children (file->gfile, NULL, + G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, + NULL, &err); + + if (err != NULL) + { + g_warning ("Failed to check if the file has any children! Reason: %s", err->message); + g_error_free (err); + return TRUE; + } + + if (g_file_enumerator_iterate (enumerator, &info, NULL, NULL, &err) && info != NULL) + is_empty = FALSE; + + g_object_unref (enumerator); + + return is_empty; +} + + + /** * thunar_file_is_shortcut: * @file : a #ThunarFile instance. diff --git a/thunar/thunar-file.h b/thunar/thunar-file.h index c9091c5dd4c2264a9bc458889ef7aa4d07a6af8e..ad213672446992695872e758c4490bbb64c7b087 100644 --- a/thunar/thunar-file.h +++ b/thunar/thunar-file.h @@ -220,6 +220,7 @@ ThunarFileMode thunar_file_get_mode (const ThunarFile gboolean thunar_file_is_mounted (const ThunarFile *file); gboolean thunar_file_exists (const ThunarFile *file); gboolean thunar_file_is_directory (const ThunarFile *file) G_GNUC_PURE; +gboolean thunar_file_is_empty_directory (const ThunarFile *file) G_GNUC_PURE; gboolean thunar_file_is_shortcut (const ThunarFile *file) G_GNUC_PURE; gboolean thunar_file_is_mountable (const ThunarFile *file) G_GNUC_PURE; gboolean thunar_file_is_local (const ThunarFile *file); diff --git a/thunar/thunar-gio-extensions.c b/thunar/thunar-gio-extensions.c index 207800e72a9a53d804395da725a8f38c40eb7df5..1fdd09ab36f5c1a3491a9026f4378a4a696580e6 100644 --- a/thunar/thunar-gio-extensions.c +++ b/thunar/thunar-gio-extensions.c @@ -1409,36 +1409,6 @@ thunar_g_file_get_link_path_for_symlink (GFile *file_to_link, -gboolean -thunar_g_file_is_empty (GFile *file) -{ - GFileEnumerator *enumerator; - GError *err = NULL; - gboolean is_empty = TRUE; - GFileInfo *info; - - _thunar_return_val_if_fail (G_IS_FILE (file), TRUE); - - enumerator = g_file_enumerate_children (file, NULL, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, &err); - - if (err != NULL) - { - g_warning ("Failed to check if the file has any children!"); - return TRUE; - } - - if (g_file_enumerator_iterate (enumerator, &info, NULL, NULL, &err) && info != NULL) - is_empty = FALSE; - - g_object_unref (enumerator); - - return is_empty; -} - - - static GFileInfo* thunar_g_file_get_content_type_querry_info (GFile *gfile, GError *err) diff --git a/thunar/thunar-gio-extensions.h b/thunar/thunar-gio-extensions.h index c3c2c706eea88404a5a7c25311dbee47e8306de5..291f387c4ee2819617186f3bf532871f7531742d 100644 --- a/thunar/thunar-gio-extensions.h +++ b/thunar/thunar-gio-extensions.h @@ -90,7 +90,6 @@ gboolean thunar_g_file_compare_checksum (GFile *file_ GFile *file_b, GCancellable *cancellable, GError **error); -gboolean thunar_g_file_is_empty (GFile *file); /** * THUNAR_TYPE_G_FILE_LIST: diff --git a/thunar/thunar-tree-view-model.c b/thunar/thunar-tree-view-model.c index 449fde7179375e1e73858bc92aab05c55505cf93..eed43f3f573c9ec202e0687e7e32b76a6ce0f346 100644 --- a/thunar/thunar-tree-view-model.c +++ b/thunar/thunar-tree-view-model.c @@ -2221,7 +2221,7 @@ thunar_tree_view_model_dir_add_file (Node *node, thunar_tree_view_model_node_add_child (node, child); if (thunar_file_is_directory (file) - && !thunar_g_file_is_empty (thunar_file_get_file (file))) + && !thunar_file_is_empty_directory (file)) thunar_tree_view_model_node_add_dummy_child (child); /* notify the model if a child has been added to previously empty folder */ @@ -2802,7 +2802,7 @@ thunar_tree_view_model_dir_files_changed (Node *node_parent, } if (thunar_file_is_directory (file) - && !thunar_g_file_is_empty (thunar_file_get_file (file)) + && !thunar_file_is_empty_directory (file) && !node->loaded && !thunar_tree_view_model_node_has_dummy_child (node)) {