aboutsummaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-07-30 04:35:34 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-07-30 04:36:19 +0800
commit69c904178f72e5eba88159a65f642d9b903a233e (patch)
tree04ab724ad6d2c19096f0d612e38ff69c234d28ac /shell
parent52ad80d6014a82cb64903d5a452083f5f923a034 (diff)
downloadgsoc2013-evolution-69c904178f72e5eba88159a65f642d9b903a233e.tar
gsoc2013-evolution-69c904178f72e5eba88159a65f642d9b903a233e.tar.gz
gsoc2013-evolution-69c904178f72e5eba88159a65f642d9b903a233e.tar.bz2
gsoc2013-evolution-69c904178f72e5eba88159a65f642d9b903a233e.tar.lz
gsoc2013-evolution-69c904178f72e5eba88159a65f642d9b903a233e.tar.xz
gsoc2013-evolution-69c904178f72e5eba88159a65f642d9b903a233e.tar.zst
gsoc2013-evolution-69c904178f72e5eba88159a65f642d9b903a233e.zip
Avoid overwriting files while migrating.
Diffstat (limited to 'shell')
-rw-r--r--shell/e-shell-migrate.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/shell/e-shell-migrate.c b/shell/e-shell-migrate.c
index 4e938ef1f6..ed6537c7df 100644
--- a/shell/e-shell-migrate.c
+++ b/shell/e-shell-migrate.c
@@ -47,14 +47,32 @@ static gboolean
shell_xdg_migrate_rename (const gchar *old_filename,
const gchar *new_filename)
{
+ gboolean old_filename_is_dir;
+ gboolean old_filename_exists;
+ gboolean new_filename_exists;
gboolean success = TRUE;
- if (g_file_test (old_filename, G_FILE_TEST_EXISTS)) {
- g_print (" mv %s %s\n", old_filename, new_filename);
+ old_filename_is_dir = g_file_test (old_filename, G_FILE_TEST_IS_DIR);
+ old_filename_exists = g_file_test (old_filename, G_FILE_TEST_EXISTS);
+ new_filename_exists = g_file_test (new_filename, G_FILE_TEST_EXISTS);
+
+ if (!old_filename_exists)
+ return TRUE;
+
+ g_print (" mv %s %s\n", old_filename, new_filename);
+
+ /* It's safe to go ahead and move directories because rename()
+ * will fail if the new directory already exists with content.
+ * With regular files we have to be careful not to overwrite
+ * new files with old files. */
+ if (old_filename_is_dir || !new_filename_exists) {
if (g_rename (old_filename, new_filename) < 0) {
g_printerr (" FAILED: %s\n", g_strerror (errno));
success = FALSE;
}
+ } else {
+ g_printerr (" FAILED: Destination file already exists\n");
+ success = FALSE;
}
return success;