[gnome-color-manager] trivial: fix up a potential crasher in gcm_utils_mkdir_for_filename()
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] trivial: fix up a potential crasher in gcm_utils_mkdir_for_filename()
- Date: Wed, 24 Feb 2010 11:08:03 +0000 (UTC)
commit 661437cf7267422f479387f2d1cdd96af86e243f
Author: Richard Hughes <richard hughsie com>
Date: Wed Feb 24 11:07:29 2010 +0000
trivial: fix up a potential crasher in gcm_utils_mkdir_for_filename()
src/gcm-utils.c | 27 +++++++++++++++++++++------
1 files changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 661303d..d10851e 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -268,23 +268,38 @@ out:
gboolean
gcm_utils_mkdir_for_filename (const gchar *filename, GError **error)
{
- gboolean ret;
+ gboolean ret = FALSE;
GFile *file;
- GFile *parent_dir;
+ GFile *parent_dir = NULL;
+ /* get a file from the URI / path */
file = g_file_new_for_uri (filename);
+ if (file == NULL)
+ file = g_file_new_for_path (filename);
+ if (file == NULL) {
+ g_set_error (error, 1, 0, "could not resolve file for %s", filename);
+ goto out;
+ }
+
+ /* get parent */
parent_dir = g_file_get_parent (file);
+ if (parent_dir == NULL) {
+ g_set_error (error, 1, 0, "could not get parent dir %s", filename);
+ goto out;
+ }
/* ensure desination exists */
- ret = g_file_test (g_file_get_path (parent_dir), G_FILE_TEST_EXISTS);
+ ret = g_file_query_exists (parent_dir, NULL);
if (!ret) {
- ret = g_file_make_directory_with_parents (parent_dir, NULL, error);
+ ret = g_file_make_directory_with_parents (parent_dir, NULL, error);
if (!ret)
goto out;
}
out:
- g_object_unref (file);
- g_object_unref (parent_dir);
+ if (file != NULL)
+ g_object_unref (file);
+ if (parent_dir != NULL)
+ g_object_unref (parent_dir);
return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]