[gthumb] Make file-overwrite optional when doing file move or copy



commit 1eae9c3d87d7fef77904b408db690665f4b34f31
Author: Michael J. Chudobiak <mjc avtechpulse com>
Date:   Tue May 19 07:59:39 2009 -0400

    Make file-overwrite optional when doing file move or copy
---
 libgthumb/comments.c                |    4 ++--
 libgthumb/file-utils.c              |    9 ++++++---
 libgthumb/file-utils.h              |    2 ++
 libgthumb/gfile-utils.c             |   17 +++++++++++++----
 libgthumb/gfile-utils.h             |    3 +++
 libgthumb/pixbuf-utils.c            |    2 +-
 libgthumb/thumb-cache.c             |    4 ++--
 src/catalog-web-exporter.c          |    2 +-
 src/dlg-catalog.c                   |    2 +-
 src/dlg-file-utils.c                |    2 +-
 src/dlg-photo-importer.c            |    2 +-
 src/gth-browser-actions-callbacks.c |   10 +++++-----
 src/main.c                          |    2 +-
 src/rotation-utils.c                |    2 +-
 14 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/libgthumb/comments.c b/libgthumb/comments.c
index 1e22e84..f6ccc63 100644
--- a/libgthumb/comments.c
+++ b/libgthumb/comments.c
@@ -224,7 +224,7 @@ comment_copy (const char *src,
 	if (path_is_file (comment_dest))
 		file_unlink (comment_dest);
 
-	file_copy (comment_src, comment_dest, NULL);
+	file_copy (comment_src, comment_dest, TRUE, NULL);
 
 	g_free (comment_src);
 	g_free (comment_dest);
@@ -248,7 +248,7 @@ comment_move (const char *src,
 	if (path_is_file (comment_dest))
 		file_unlink (comment_dest);
 
-	file_move (comment_src, comment_dest, NULL);
+	file_move (comment_src, comment_dest, TRUE, NULL);
 
 	g_free (comment_src);
 	g_free (comment_dest);
diff --git a/libgthumb/file-utils.c b/libgthumb/file-utils.c
index dc8fdb4..de53f05 100644
--- a/libgthumb/file-utils.c
+++ b/libgthumb/file-utils.c
@@ -572,6 +572,7 @@ static gboolean
 xfer_file (const char *from,
 	   const char *to,
 	   gboolean    move,
+           gboolean    overwrite,
 	   GError    **error)
 {
 	GFile      *sfile;
@@ -581,7 +582,7 @@ xfer_file (const char *from,
 	sfile = gfile_new (from);
 	dfile = gfile_new (to);
 	
-	result = gfile_xfer (sfile, dfile, move, error);
+	result = gfile_xfer (sfile, dfile, move, overwrite, error);
 
 	g_object_unref (sfile);
 	g_object_unref (dfile);
@@ -593,18 +594,20 @@ xfer_file (const char *from,
 gboolean
 file_copy (const char *from,
 	   const char *to,
+	   gboolean    overwrite,
 	   GError    **error)
 {
-	return xfer_file (from, to, FALSE, error);
+	return xfer_file (from, to, overwrite, FALSE, error);
 }
 
 
 gboolean
 file_move (const char *from,
 	   const char *to,
+           gboolean    overwrite,
 	   GError    **error)
 {
-	return xfer_file (from, to, TRUE, error);
+	return xfer_file (from, to, overwrite, TRUE, error);
 }
 
 
diff --git a/libgthumb/file-utils.h b/libgthumb/file-utils.h
index 7a395d6..de45363 100644
--- a/libgthumb/file-utils.h
+++ b/libgthumb/file-utils.h
@@ -117,9 +117,11 @@ gboolean            file_is_image_video_or_audio  (const gchar      *name,
 gboolean            file_is_hidden                (const char       *name);
 gboolean            file_copy                     (const char       *from,
 						   const char       *to,
+                                                   gboolean          overwrite,
 						   GError	   **error);
 gboolean            file_move                     (const char       *from,
 						   const char       *to,
+					           gboolean          overwrite,
 						   GError	   **error);
 void                file_unlink_with_gerror       (const char  *full_path,
                                                    GError     **gerror);
diff --git a/libgthumb/gfile-utils.c b/libgthumb/gfile-utils.c
index 3b870f5..18a6da7 100644
--- a/libgthumb/gfile-utils.c
+++ b/libgthumb/gfile-utils.c
@@ -763,10 +763,17 @@ gboolean
 gfile_xfer (GFile    *sfile,
             GFile    *dfile,
             gboolean  move,
+            gboolean  overwrite,
 	    GError  **error)
 {
+	int     attr;
 	GError *priv_error = NULL;
 
+	if (overwrite)
+		attr = G_FILE_COPY_OVERWRITE;
+	else
+		attr = G_FILE_COPY_NONE;
+
         if (error == NULL)
                 error = &priv_error;
 
@@ -775,7 +782,7 @@ gfile_xfer (GFile    *sfile,
 #if GLIB_CHECK_VERSION(2,19,0)
 			     G_FILE_COPY_TARGET_DEFAULT_PERMS |
 #endif 
-                             G_FILE_COPY_NONE,
+                             attr,
                              NULL, _empty_file_progress_cb,
                              NULL, error);
         else
@@ -783,7 +790,7 @@ gfile_xfer (GFile    *sfile,
 #if GLIB_CHECK_VERSION(2,19,0)
                              G_FILE_COPY_TARGET_DEFAULT_PERMS |
 #endif 
-                             G_FILE_COPY_NONE,
+                             attr,
                              NULL, _empty_file_progress_cb,
                              NULL, error);
 
@@ -800,17 +807,19 @@ gfile_xfer (GFile    *sfile,
 gboolean
 gfile_copy (GFile   *sfile,
             GFile   *dfile,
+            gboolean overwrite,
 	    GError **error)
 {
-        return gfile_xfer (sfile, dfile, FALSE, error);
+        return gfile_xfer (sfile, dfile, FALSE, overwrite, error);
 }
 
 gboolean
 gfile_move (GFile   *sfile,
             GFile   *dfile,
+            gboolean overwrite,
 	    GError **error)
 {
-        return gfile_xfer (sfile, dfile, TRUE, error);
+        return gfile_xfer (sfile, dfile, TRUE, overwrite, error);
 }
 
 
diff --git a/libgthumb/gfile-utils.h b/libgthumb/gfile-utils.h
index 4991998..209eaeb 100644
--- a/libgthumb/gfile-utils.h
+++ b/libgthumb/gfile-utils.h
@@ -92,12 +92,15 @@ gboolean      gfile_path_list_new              (GFile      *gfile,
 gboolean      gfile_xfer                       (GFile      *sfile,
 		                                GFile      *dfile,
 		                                gboolean    move,
+                                                gboolean    overwrite,
 						GError    **error);
 gboolean      gfile_copy                       (GFile      *sfile,
 		                                GFile      *dfile,
+                                                gboolean    overwrite,
 						GError    **error);
 gboolean      gfile_move                       (GFile      *sfile,
 		                                GFile      *dfile,
+                                                gboolean    overwrite,
 						GError    **error);
 /* line-based read/write */
 gssize        gfile_output_stream_write_line   (GFileOutputStream *ostream,
diff --git a/libgthumb/pixbuf-utils.c b/libgthumb/pixbuf-utils.c
index 8603c8c..7985af6 100644
--- a/libgthumb/pixbuf-utils.c
+++ b/libgthumb/pixbuf-utils.c
@@ -1229,7 +1229,7 @@ _gdk_pixbuf_savev (GdkPixbuf    *pixbuf,
 				ext = get_filename_extension (original_local_file);
 				temp_backup = get_temp_file_name (temp_dir, ext);
 				g_free (ext);
-				file_copy (original_local_file, temp_backup, NULL);
+				file_copy (original_local_file, temp_backup, TRUE, NULL);
 			}
 		}
 	}
diff --git a/libgthumb/thumb-cache.c b/libgthumb/thumb-cache.c
index cf202eb..a2c112b 100644
--- a/libgthumb/thumb-cache.c
+++ b/libgthumb/thumb-cache.c
@@ -95,7 +95,7 @@ cache_copy (const char *src,
 
 		if (path_is_file (cache_dest))
 			file_unlink (cache_dest);
-		if (file_copy (cache_src, cache_dest, NULL))
+		if (file_copy (cache_src, cache_dest, TRUE, NULL))
 			set_file_mtime (cache_dest, dest_mtime);
 
 		g_free (cache_dest);
@@ -118,7 +118,7 @@ cache_move (const char *src,
 
 		if (path_is_file (cache_dest))
 			file_unlink (cache_dest);
-		if (file_move (cache_src, cache_dest, NULL))
+		if (file_move (cache_src, cache_dest, TRUE, NULL))
 			set_file_mtime (cache_dest, dest_mtime);
 
 		g_free (cache_dest);
diff --git a/src/catalog-web-exporter.c b/src/catalog-web-exporter.c
index 22c001a..c3876ad 100644
--- a/src/catalog-web-exporter.c
+++ b/src/catalog-web-exporter.c
@@ -2707,7 +2707,7 @@ export__copy_image (CatalogWebExporter *ce)
 			        idata, 
 			        ce->target_tmp_dir);
 		
-	copy_done = gfile_copy (sfile, dfile, NULL);
+	copy_done = gfile_copy (sfile, dfile, TRUE, NULL);
 
 	if (copy_done) {
 		if (gfile_image_is_jpeg (dfile)) {
diff --git a/src/dlg-catalog.c b/src/dlg-catalog.c
index 7984c0f..a926a98 100644
--- a/src/dlg-catalog.c
+++ b/src/dlg-catalog.c
@@ -417,7 +417,7 @@ move_to_catalog_dir__ok_cb (GtkWidget  *widget,
 				file_name_from_path (data->data.catalog_path),
 				NULL);
 
-	file_move (data->data.catalog_path, new_path, NULL);
+	file_move (data->data.catalog_path, new_path, TRUE, NULL);
 
 	g_free (new_path);
 	g_free (new_dir);
diff --git a/src/dlg-file-utils.c b/src/dlg-file-utils.c
index 57f491f..e51099d 100644
--- a/src/dlg-file-utils.c
+++ b/src/dlg-file-utils.c
@@ -1026,7 +1026,7 @@ dlg_file_rename_series (GthWindow *window,
 			continue;
 		}
 
-		file_move (old_full_path, new_full_path, &gerror);
+		file_move (old_full_path, new_full_path, TRUE, &gerror);
 		if (gerror == NULL) {
 			cache_move (old_full_path, new_full_path);
 			comment_move (old_full_path, new_full_path);
diff --git a/src/dlg-photo-importer.c b/src/dlg-photo-importer.c
index 3970fdc..2764710 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) ) {
-				if (!file_move (initial_dest_path, final_dest_path, NULL)) {
+				if (!file_move (initial_dest_path, final_dest_path, TRUE, NULL)) {
 					error_found = TRUE;
 				}
 			} else {
diff --git a/src/gth-browser-actions-callbacks.c b/src/gth-browser-actions-callbacks.c
index 7f128d3..0be1e53 100644
--- a/src/gth-browser-actions-callbacks.c
+++ b/src/gth-browser-actions-callbacks.c
@@ -252,7 +252,7 @@ duplicate_file (GtkWindow  *window,
 	g_free (dir);
 	g_free (old_name_no_ext);
 
-	if (file_copy (old_path, new_path, NULL)) {
+	if (file_copy (old_path, new_path, FALSE, NULL)) {
 		cache_copy (old_path, new_path);
 		comment_copy (old_path, new_path);
 	} 
@@ -498,7 +498,7 @@ catalog_rename (GthBrowser *browser,
 		_gtk_error_dialog_run (GTK_WINDOW (browser),
 				       _("The name \"%s\" is already used. " "Please use a different name."), new_fd->utf8_name);
 	} 
-	else if (file_move (old_fd->path,new_fd->path, NULL)) {
+	else if (file_move (old_fd->path,new_fd->path, FALSE, NULL)) {
 		all_windows_notify_catalog_rename (old_fd->path,new_fd->path);
 	} 
 	else {
@@ -973,7 +973,7 @@ folder_rename (GtkWindow  *window,
 	else {
 		gboolean        result;
 
-		result = file_move (old_fd->path, new_fd->utf8_path, NULL);
+		result = file_move (old_fd->path, new_fd->utf8_path, FALSE, NULL);
 		if (result) {
 			comment_move (old_path, new_path);
 			all_windows_notify_directory_rename (old_fd->path, new_fd->path);
@@ -1256,7 +1256,7 @@ folder_copy__response_cb (GObject *object,
 
 		old_folder_comment = comments_get_comment_filename (old_path, TRUE);
 
-		file_move (old_fd->utf8_path, new_fd->utf8_path, &error);
+		file_move (old_fd->utf8_path, new_fd->utf8_path, FALSE, &error);
 		if (!error) {
 			char *new_folder_comment;
 
@@ -1264,7 +1264,7 @@ folder_copy__response_cb (GObject *object,
 			 * implemeted with rename, which is faster. */
 
 			new_folder_comment = comments_get_comment_filename (new_path, TRUE);
-			file_move (old_folder_comment, new_folder_comment, NULL);
+			file_move (old_folder_comment, new_folder_comment, TRUE, NULL);
 			g_free (new_folder_comment);
 
 			all_windows_notify_directory_rename (old_path, new_path);
diff --git a/src/main.c b/src/main.c
index 393864b..62aa196 100644
--- a/src/main.c
+++ b/src/main.c
@@ -189,7 +189,7 @@ convert_old_comment (char     *real_file,
 	comment_dir = remove_level_from_path (comment_file);
 	ensure_dir_exists (comment_dir);
 
-	file_copy (rc_file, comment_file, NULL);
+	file_copy (rc_file, comment_file, TRUE, NULL);
 
 	g_free (comment_dir);
 	g_free (comment_file);
diff --git a/src/rotation-utils.c b/src/rotation-utils.c
index cce9679..489e309 100644
--- a/src/rotation-utils.c
+++ b/src/rotation-utils.c
@@ -203,7 +203,7 @@ apply_transformation_jpeg (FileData       *file,
 		goto apply_transformation_jpeg__free_and_close;
 	}
 
-	if (! file_move (tmp_output_file, file->local_path, NULL)) {
+	if (! file_move (tmp_output_file, file->local_path, TRUE, NULL)) {
 		if (error != NULL)
 			*error = g_error_new (GTHUMB_ERROR, 0, "%s", _("Could not move temporary file to local destination. Check folder permissions."));
 		result = FALSE;



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