comparison src/audacious/util.c @ 2989:15f6c9949cde trunk

Add and use find_path_recursively() which search the FS without using VFS (for GTK).
author William Pitcock <nenolod@atheme-project.org>
date Thu, 05 Jul 2007 01:40:11 -0500
parents 43a075cb5c81
children 3a907327e228
comparison
equal deleted inserted replaced
2988:43a075cb5c81 2989:15f6c9949cde
77 if (strlen(path) > FILENAME_MAX) { 77 if (strlen(path) > FILENAME_MAX) {
78 g_warning("Ignoring path: name too long (%s)", path); 78 g_warning("Ignoring path: name too long (%s)", path);
79 return TRUE; 79 return TRUE;
80 } 80 }
81 81
82 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { 82 if (vfs_file_test(path, G_FILE_TEST_IS_REGULAR)) {
83 if (!strcasecmp(basename, context->to_match)) { 83 if (!strcasecmp(basename, context->to_match)) {
84 context->match = g_strdup(path); 84 context->match = g_strdup(path);
85 context->found = TRUE; 85 context->found = TRUE;
86 return TRUE; 86 return TRUE;
87 } 87 }
88 } 88 }
89 else if (g_file_test(path, G_FILE_TEST_IS_DIR)) { 89 else if (vfs_file_test(path, G_FILE_TEST_IS_DIR)) {
90 dir_foreach(path, find_file_func, context, NULL); 90 dir_foreach(path, find_file_func, context, NULL);
91 if (context->found) 91 if (context->found)
92 return TRUE; 92 return TRUE;
93 } 93 }
94 94
97 97
98 gchar * 98 gchar *
99 find_file_recursively(const gchar * path, const gchar * filename) 99 find_file_recursively(const gchar * path, const gchar * filename)
100 { 100 {
101 FindFileContext context; 101 FindFileContext context;
102 gchar *out; 102 gchar *out = NULL;
103 103
104 context.to_match = filename; 104 context.to_match = filename;
105 context.match = NULL; 105 context.match = NULL;
106 context.found = FALSE; 106 context.found = FALSE;
107 107
108 dir_foreach(path, find_file_func, &context, NULL); 108 dir_foreach(path, find_file_func, &context, NULL);
109 out = g_strconcat("file:", context.match); 109
110 g_free(context.match); 110 if (context.match)
111 {
112 out = g_filename_to_uri(context.match, NULL, NULL);
113 g_free(context.match);
114 }
111 115
112 return out; 116 return out;
117 }
118
119 gchar *
120 find_path_recursively(const gchar * path, const gchar * filename)
121 {
122 FindFileContext context;
123 gchar *out = NULL;
124
125 context.to_match = filename;
126 context.match = NULL;
127 context.found = FALSE;
128
129 dir_foreach(path, find_file_func, &context, NULL);
130
131 return context.match;
113 } 132 }
114 133
115 134
116 typedef enum { 135 typedef enum {
117 ARCHIVE_UNKNOWN = 0, 136 ARCHIVE_UNKNOWN = 0,