[rhythmbox] file-helpers: make rb_uri_handle_recursively work for single files
- From: Jonathan Matthew <jmatthew src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rhythmbox] file-helpers: make rb_uri_handle_recursively work for single files
- Date: Mon, 22 Feb 2010 21:04:58 +0000 (UTC)
commit 05f676dfa480c90c696f1f0e1f229efa24921eba
Author: Jonathan Matthew <jonathan d14n org>
Date: Tue Feb 23 06:35:20 2010 +1000
file-helpers: make rb_uri_handle_recursively work for single files
Now that we're using it for general import operations, it needs to try
as hard as possible to do something useful.
lib/rb-file-helpers.c | 32 +++++++++++++++++++++++++-------
1 files changed, 25 insertions(+), 7 deletions(-)
---
diff --git a/lib/rb-file-helpers.c b/lib/rb-file-helpers.c
index 8b7acc9..5466b8d 100644
--- a/lib/rb-file-helpers.c
+++ b/lib/rb-file-helpers.c
@@ -582,6 +582,14 @@ typedef struct {
GList *dir_results;
} RBUriHandleRecursivelyAsyncData;
+static gboolean
+_should_process (GFileInfo *info)
+{
+ /* check that the file is non-hidden and readable */
+ return (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) &&
+ (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) == FALSE));
+}
+
static void
_uri_handle_recurse (GFile *dir,
GCancellable *cancel,
@@ -605,6 +613,20 @@ _uri_handle_recurse (GFile *dir,
files = g_file_enumerate_children (dir, attributes, G_FILE_QUERY_INFO_NONE, cancel, &error);
if (error != NULL) {
char *where;
+
+ /* handle the case where we're given a single file to process */
+ if (error->code == G_IO_ERROR_NOT_DIRECTORY) {
+ g_clear_error (&error);
+ info = g_file_query_info (dir, attributes, G_FILE_QUERY_INFO_NONE, cancel, &error);
+ if (error == NULL) {
+ if (_should_process (info)) {
+ (func) (dir, FALSE, user_data);
+ }
+ g_object_unref (info);
+ return;
+ }
+ }
+
where = g_file_get_uri (dir);
rb_debug ("error enumerating %s: %s", where, error->message);
g_free (where);
@@ -626,13 +648,8 @@ _uri_handle_recurse (GFile *dir,
break;
}
- child = g_file_get_child (dir, g_file_info_get_name (info));
-
- /* is non-hidden and readable? */
- if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) == FALSE ||
- g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN)) {
+ if (_should_process (info) == FALSE) {
g_object_unref (info);
- g_object_unref (child);
continue;
}
@@ -662,15 +679,16 @@ _uri_handle_recurse (GFile *dir,
}
if (file_handled == FALSE) {
+ child = g_file_get_child (dir, g_file_info_get_name (info));
ret = (func) (child, is_dir, user_data);
if (is_dir) {
_uri_handle_recurse (child, cancel, handled, func, user_data);
}
+ g_object_unref (child);
}
g_object_unref (info);
- g_object_unref (child);
if (ret == FALSE)
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]