[gthumb] Don't force non-default permission on new folders or their parents



commit 4ec002e2539d893f1b6acb84e91a4014d851378c
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Tue May 12 08:30:28 2009 -0400

    Don't force non-default permission on new folders or their parents
---
 libgthumb/comments.c       |    2 +-
 libgthumb/file-utils.c     |    7 ++---
 libgthumb/file-utils.h     |    3 +-
 libgthumb/gfile-utils.c    |   50 ++++++++++++++++++++++++++++---------------
 libgthumb/gfile-utils.h    |    1 -
 libgthumb/gthumb-init.c    |    8 +++---
 libgthumb/thumb-loader.c   |    4 +--
 src/catalog-web-exporter.c |    4 +-
 src/dlg-file-utils.c       |    6 ++--
 src/dlg-photo-importer.c   |    4 +-
 src/dlg-web-exporter.c     |    2 +-
 src/main.c                 |    2 +-
 12 files changed, 51 insertions(+), 42 deletions(-)

diff --git a/libgthumb/comments.c b/libgthumb/comments.c
index ccc1532..3f9fe94 100644
--- a/libgthumb/comments.c
+++ b/libgthumb/comments.c
@@ -585,7 +585,7 @@ save_comment (const char  *uri,
 
 	if (file_data_has_local_path (fd, NULL)) {
 		dest_dir = remove_level_from_path (fd->local_path);
-		if (ensure_dir_exists (dest_dir, 0700)) {
+		if (ensure_dir_exists (dest_dir)) {
 			xmlSetDocCompressMode (doc, 3);
 			xmlSaveFile (fd->local_path, doc);
 		}
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index f911130..b1aeca3 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -381,8 +381,7 @@ local_dir_remove_recursive (const char *path)
 
 
 gboolean
-ensure_dir_exists (const char *path,
-		   mode_t      mode)
+ensure_dir_exists (const char *path)
 {
 	GFile    *gfile;
 	gboolean  result;
@@ -391,7 +390,7 @@ ensure_dir_exists (const char *path,
 		return FALSE;
 
 	gfile = gfile_new (path);
-	result = gfile_ensure_dir_exists (gfile, mode, NULL);
+	result = gfile_ensure_dir_exists (gfile, NULL);
 	
 	g_object_unref (gfile);
 	return result;
@@ -3032,7 +3031,7 @@ xdg_user_dir_lookup (const char *type)
 	fclose (file);
 
 	if (user_dir) {
-		ensure_dir_exists (user_dir, 0775);
+		ensure_dir_exists (user_dir);
 		return user_dir;
 	}
 
diff --git a/libgthumb/file-utils.h b/libgthumb/file-utils.h
index c3bbd41..bc7bd14 100644
--- a/libgthumb/file-utils.h
+++ b/libgthumb/file-utils.h
@@ -92,8 +92,7 @@ gboolean            dir_remove                    (const char       *uri);
 gboolean            dir_remove_recursive          (const char       *path);
 gboolean            local_dir_remove_recursive    (const char       *path);
 
-gboolean            ensure_dir_exists             (const char       *path,
-						   mode_t            mode);
+gboolean            ensure_dir_exists             (const char       *path);
 GList *             dir_list_filter_and_sort      (GList            *dir_list,
 						   gboolean          names_only,
 						   gboolean          show_dot_files);
diff --git a/libgthumb/gfile-utils.c b/libgthumb/gfile-utils.c
index 53b14c7..fab36c3 100644
--- a/libgthumb/gfile-utils.c
+++ b/libgthumb/gfile-utils.c
@@ -428,62 +428,76 @@ gfile_get_display_name (GFile *file)
 
 static gboolean
 _gfile_make_directory_tree (GFile    *dir,
-                            mode_t    mode,
                             GError  **error)
 {
         gboolean  success = TRUE;
         GFile    *parent;
 
+	if (gfile_path_is_dir (dir))
+		return TRUE;
+
         parent = g_file_get_parent (dir);
         if (parent != NULL) {
-                success = _gfile_make_directory_tree (parent, mode, error);
+                success = _gfile_make_directory_tree (parent, error);
                 g_object_unref (parent);
                 if (! success)
                         return FALSE;
         }
 
-        success = gfile_path_is_dir (dir) || g_file_make_directory (dir, NULL, error);
+        success = g_file_make_directory (dir, NULL, error);
         if ((error != NULL) && (*error != NULL) && g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_EXISTS)) {
                 g_clear_error (error);
                 success = TRUE;
         }
 
-        if (success)
-                g_file_set_attribute_uint32 (dir,
-                                             G_FILE_ATTRIBUTE_UNIX_MODE,
-                                             mode,
-                                             0,
-                                             NULL,
-                                             NULL);
-
         return success;
 }
 
 
 gboolean
 gfile_ensure_dir_exists (GFile    *dir,
-                         mode_t    mode,
                          GError  **error)
 {
-        GError *priv_error = NULL;
+        GError    *priv_error = NULL;
+	GFileInfo *info;
+	gboolean   result;
 
-        //FIXME: shouldn't we get rid of this test and fix the callers instead?
         if (dir == NULL)
                 return FALSE;
 
         if (error == NULL)
                 error = &priv_error;
 
-        if (! _gfile_make_directory_tree (dir, mode, error)) {
-
+	/* Try making dir and any needed parent dirs */
+        if (! _gfile_make_directory_tree (dir, error)) {
                 gfile_warning ("could not create directory", dir, *error);
                 if (priv_error != NULL)
                         g_clear_error (&priv_error);
-
                 return FALSE;
         }
 
-        return TRUE;
+	/* Can we read, write, and execute the new dir? */
+        info = g_file_query_info (dir,
+                                  G_FILE_ATTRIBUTE_ACCESS_CAN_READ ","
+                                  G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE ","
+                                  G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE,
+                                  G_FILE_QUERY_INFO_NONE,
+                                  NULL,
+                                  error);
+
+        if (info == NULL) {
+                gfile_warning ("Failed to get directory permission information", dir, *error);
+		if (priv_error != NULL)
+                        g_clear_error (&priv_error);
+                result = FALSE;
+        } else {
+                result = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) &&
+                         g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE) &&
+                         g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE);
+        }
+
+        g_object_unref (info);
+        return result;
 }
 
 
diff --git a/libgthumb/gfile-utils.h b/libgthumb/gfile-utils.h
index c2abf22..622ff4e 100644
--- a/libgthumb/gfile-utils.h
+++ b/libgthumb/gfile-utils.h
@@ -79,7 +79,6 @@ char *        gfile_get_display_name           (GFile      *file);
 /* Directory utils */
 
 gboolean      gfile_ensure_dir_exists          (GFile      *dir,
-			                        mode_t      mode,
 			                        GError    **error);
 guint64       gfile_get_destination_free_space (GFile      *file);
 GFile *       gfile_get_home_dir               (void);
diff --git a/libgthumb/gthumb-init.c b/libgthumb/gthumb-init.c
index 64adeb3..831a9fd 100644
--- a/libgthumb/gthumb-init.c
+++ b/libgthumb/gthumb-init.c
@@ -55,15 +55,15 @@ ensure_directories_exist (void)
 	g_free (path);
 
 	path = get_home_relative_dir (RC_CATALOG_DIR);
-	ensure_dir_exists (path, 0700);
+	ensure_dir_exists (path);
 	g_free (path);
 
 	path = get_home_relative_dir (RC_COMMENTS_DIR);
-	ensure_dir_exists (path, 0700);
+	ensure_dir_exists (path);
 	g_free (path);
 
 	path = get_home_relative_dir (RC_REMOTE_CACHE_DIR);
-        ensure_dir_exists (path, 0700);
+        ensure_dir_exists (path);
         g_free (path);
 }
 
@@ -147,7 +147,7 @@ gthumb_init ()
 	char *path;
 
 	path = get_home_relative_dir (RC_DIR);
-	ensure_dir_exists (path, 0700);
+	ensure_dir_exists (path);
 	g_free (path);
 
 	if (eel_gconf_get_boolean (PREF_MIGRATE_DIRECTORIES, TRUE))
diff --git a/libgthumb/thumb-loader.c b/libgthumb/thumb-loader.c
index 9ad2b34..661f288 100644
--- a/libgthumb/thumb-loader.c
+++ b/libgthumb/thumb-loader.c
@@ -47,8 +47,6 @@
 #define THUMBNAIL_LARGE_SIZE	256
 #define THUMBNAIL_NORMAL_SIZE	128
 
-#define THUMBNAIL_DIR_PERMISSIONS 0700
-
 struct _ThumbLoaderPrivateData
 {
 	FileData              *file;
@@ -484,7 +482,7 @@ thumb_loader_save_to_cache (ThumbLoader *tl)
 	cache_dir = remove_level_from_path (cache_file);
 	g_free (cache_file);
 
-	if (ensure_dir_exists (cache_dir, THUMBNAIL_DIR_PERMISSIONS))	
+	if (ensure_dir_exists (cache_dir))	
 		gnome_thumbnail_factory_save_thumbnail (tl->priv->thumb_factory,
 							tl->priv->pixbuf,
 							tl->priv->file->path,
diff --git a/src/catalog-web-exporter.c b/src/catalog-web-exporter.c
index e17749f..089ca00 100644
--- a/src/catalog-web-exporter.c
+++ b/src/catalog-web-exporter.c
@@ -3063,7 +3063,7 @@ ensure_album_dir_exists (GFile *target_dir,
 	
 	dir = gfile_append_path (target_dir, subdir, NULL);
 	
-	ok = gfile_ensure_dir_exists (dir, 0700, NULL);
+	ok = gfile_ensure_dir_exists (dir, NULL);
 	
 	g_object_unref (dir);
 
@@ -3075,7 +3075,7 @@ static void
 ensure_dir_structure (CatalogWebExporter *ce,
 		      GFile              *target_dir)
 {
-	gfile_ensure_dir_exists (target_dir, 0700, NULL);
+	gfile_ensure_dir_exists (target_dir, NULL);
 	
 	if (ce->use_subfolders) {
 		ensure_album_dir_exists (target_dir, ce->ad->previews);
diff --git a/src/dlg-file-utils.c b/src/dlg-file-utils.c
index 6628e3a..2c5f21d 100644
--- a/src/dlg-file-utils.c
+++ b/src/dlg-file-utils.c
@@ -143,7 +143,7 @@ dlg_check_folder (GthWindow  *window,
 		return FALSE;
 	}
 
-	if (! ensure_dir_exists (dir, 0755)) {
+	if (! ensure_dir_exists (dir)) {
 		char *utf8_path;
 		utf8_path = get_utf8_display_name_from_uri (dir);
 		_gtk_error_dialog_run (GTK_WINDOW (window),
@@ -1531,7 +1531,7 @@ copy_next_file (FileCopyData *fcdata)
 			char *parent_dir;
 
 			parent_dir = remove_level_from_path (dest_cache_file);
-			ensure_dir_exists (parent_dir, 0755);
+			ensure_dir_exists (parent_dir);
 			g_free (parent_dir);
 
 			src_list = g_list_append (src_list, new_uri_from_path (src_cache_file));
@@ -1548,7 +1548,7 @@ copy_next_file (FileCopyData *fcdata)
 
 		if (path_is_file (src_cache_file)) {
 			char *parent_dir = remove_level_from_path (dest_cache_file);
-			ensure_dir_exists (parent_dir, 0755);
+			ensure_dir_exists (parent_dir);
 			g_free (parent_dir);
 
 			src_list = g_list_append (src_list, new_uri_from_path (src_cache_file));
diff --git a/src/dlg-photo-importer.c b/src/dlg-photo-importer.c
index 8cdc2e6..46d4ac3 100644
--- a/src/dlg-photo-importer.c
+++ b/src/dlg-photo-importer.c
@@ -1351,7 +1351,7 @@ save_image (DialogData *data,
 
 			/* Create the subfolder if necessary, and move the 
 			   temporary file to it */
-			if (ensure_dir_exists (dest_folder, 0755) ) {
+			if (ensure_dir_exists (dest_folder) ) {
 				if (!file_move (initial_dest_path, final_dest_path)) {
 					error_found = TRUE;
 				}
@@ -1692,7 +1692,7 @@ ok_clicked_cb (GtkButton  *button,
 
 	folder_fd = file_data_new (data->local_folder);
 	if (!file_data_has_local_path (folder_fd, GTK_WINDOW (data->dialog)) || 
-	    !ensure_dir_exists (folder_fd->local_path, 0755)) {
+	    !ensure_dir_exists (folder_fd->local_path)) {
 		char *msg;
 		msg = g_strdup_printf (_("Could not create the folder \"%s\": %s"),
 				       folder_fd->utf8_name,
diff --git a/src/dlg-web-exporter.c b/src/dlg-web-exporter.c
index e1c5842..a2a2dbb 100644
--- a/src/dlg-web-exporter.c
+++ b/src/dlg-web-exporter.c
@@ -850,7 +850,7 @@ theme_dialog__go_to_folder_clicked (GtkWidget       *widget,
 	path = g_strdup_printf ("file://%s/.gnome2/gthumb/albumthemes",
 			       g_get_home_dir ());
 
-	ensure_dir_exists (path, 0775);
+	ensure_dir_exists (path);
 
 	if (! gnome_url_show (path, &err))
 		_gtk_error_dialog_from_gerror_run (GTK_WINDOW (tdata->dialog),
diff --git a/src/main.c b/src/main.c
index 535c27f..5210013 100644
--- a/src/main.c
+++ b/src/main.c
@@ -187,7 +187,7 @@ convert_old_comment (char     *real_file,
 
 	comment_file = comments_get_comment_filename (real_file, TRUE);
 	comment_dir = remove_level_from_path (comment_file);
-	ensure_dir_exists (comment_dir, 0755);
+	ensure_dir_exists (comment_dir);
 
 	file_copy (rc_file, comment_file);
 



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