mu: overwrite duplicate target files
over write target files when moving (when they seem to be the same). Should make the case where you have copies a bit smoother.
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/
|
||||
|
||||
/*
|
||||
** Copyright (C) 2008-2013 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
** Copyright (C) 2008-2015 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or modify it
|
||||
** under the terms of the GNU General Public License as published by the
|
||||
@ -807,9 +807,30 @@ mu_maildir_get_new_path (const char *oldpath, const char *new_mdir,
|
||||
return newpath;
|
||||
}
|
||||
|
||||
|
||||
static gint64
|
||||
get_file_size (const char* path)
|
||||
{
|
||||
int rv;
|
||||
struct stat statbuf;
|
||||
|
||||
rv = stat (path, &statbuf);
|
||||
if (rv != 0) {
|
||||
/* g_warning ("error: %s", strerror (errno)); */
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (gint64)statbuf.st_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
msg_move_check_pre (const gchar *src, const gchar *dst, GError **err)
|
||||
{
|
||||
gint size1, size2;
|
||||
|
||||
if (!g_path_is_absolute(src))
|
||||
return mu_util_g_set_error
|
||||
(err, MU_ERROR_FILE,
|
||||
@ -824,7 +845,16 @@ msg_move_check_pre (const gchar *src, const gchar *dst, GError **err)
|
||||
return mu_util_g_set_error (err, MU_ERROR_FILE,
|
||||
"cannot read %s", src);
|
||||
|
||||
if (access (dst, F_OK) == 0)
|
||||
if (access (dst, F_OK) != 0)
|
||||
return TRUE;
|
||||
|
||||
/* target exist; we simply overwrite it, unless target has a different
|
||||
* size. ignore the exceedingly rare case where have duplicate message
|
||||
* file names with different content yet the same length. (md5 etc. is a
|
||||
* bit slow) */
|
||||
size1 = get_file_size (src);
|
||||
size2 = get_file_size (dst);
|
||||
if (size1 != size2)
|
||||
return mu_util_g_set_error (err, MU_ERROR_FILE,
|
||||
"%s already exists", dst);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user