From f67b551460f6da5555d54a95b4f475ebc99bf386 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 25 May 2020 21:26:00 +0300 Subject: [PATCH] mu-maildir: avoid unnecessarily moving new-name files When calling mu_maildir_move_message with the new_name options (workaround for mbsync's), do the src=target check *without* first creating that new name. This avoids some unnecessary moves. --- lib/mu-maildir.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/mu-maildir.c b/lib/mu-maildir.c index 50e10e0e..7cc55658 100644 --- a/lib/mu-maildir.c +++ b/lib/mu-maildir.c @@ -1,7 +1,7 @@ /* -*-mode: c; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-*/ /* -** Copyright (C) 2008-2016 Dirk-Jan C. Binnema +** Copyright (C) 2008-2020 Dirk-Jan C. Binnema ** ** 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 @@ -913,14 +913,16 @@ mu_maildir_move_message (const char* oldpath, const char* targetmdir, MuFlags newflags, gboolean ignore_dups, gboolean new_name, GError **err) { - char *newfullpath; - gboolean rv; - gboolean src_is_target; + char *newfullpath; + gboolean rv; + gboolean src_is_target; g_return_val_if_fail (oldpath, FALSE); + /* first try *without* changing the name (as per new_name), since + * src_is_target shouldn't use a changed name */ newfullpath = mu_maildir_get_new_path (oldpath, targetmdir, - newflags, new_name); + newflags, FALSE); if (!newfullpath) { mu_util_g_set_error (err, MU_ERROR_FILE, "failed to determine targetpath"); @@ -928,13 +930,25 @@ mu_maildir_move_message (const char* oldpath, const char* targetmdir, } src_is_target = (g_strcmp0 (oldpath, newfullpath) == 0); - if (!ignore_dups && src_is_target) { mu_util_g_set_error (err, MU_ERROR_FILE_TARGET_EQUALS_SOURCE, "target equals source"); return NULL; } + /* if we generated file is not the same (modulo flags), create a fully + * new name in the new_name case */ + if (!src_is_target && new_name) { + g_free(newfullpath); + newfullpath = mu_maildir_get_new_path (oldpath, targetmdir, + newflags, new_name); + if (!newfullpath) { + mu_util_g_set_error (err, MU_ERROR_FILE, + "failed to determine targetpath"); + return NULL; + } + } + if (!src_is_target) { rv = msg_move (oldpath, newfullpath, err); if (!rv) {