diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-12-17 09:06:15 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-12-17 11:30:45 +0200 |
commit | 7324f9691545126806bbe219607248c7ad854852 (patch) | |
tree | b03008efade4cbd6ff1f7f49fc467d6140ee7da5 /imap4d | |
parent | e87f373e24cd64b77e9b66348fc8aa0c53de5d52 (diff) | |
download | mailutils-7324f9691545126806bbe219607248c7ad854852.tar.gz mailutils-7324f9691545126806bbe219607248c7ad854852.tar.bz2 |
Improve rename/copy/reomove API.
* examples/rename.c: Remove.
* examples/fcopy.c: New file.
* examples/fremove.c: New file.
* examples/frename.c: New file.
* examples/Makefile.am: Update.
* include/mailutils/util.h (mu_rename_file): Add flags.
(mu_remove_file): New function.
(MU_COPY_OVERWRITE): New flag.
* libmailutils/base/renamefile.c: New file.
* libmailutils/base/Makefile.am: Add newe file.
* libmailutils/base/copyfile.c: Fix error handling.
* libmailutils/base/renamefile.c (mu_rename_file): Refuse to proceed if
the destination file exists and MU_COPY_OVERWRITE flag is not set
* libmailutils/diag/errors (MU_ERR_REMOVE_SOURCE)
(MU_ERR_RESTORE_META): New errors
* imap4d/rename.c (imap4d_rename): Use mu_rename_file
* mh/forw.c: Likewise.
* mh/mh_whatnow.c: Likewise.
* mh/mhn.c: Likewise.
* mh/send.c: Likewise.
* include/mailutils/cstr.h (mu_str_count): New proto.
* include/mailutils/util.h (mu_file_name_is_safe): New proto.
* libmailutils/string/safefilename.c: New file.
* libmailutils/string/strcount.c: New file.
* libmailutils/string/Makefile.am: Update.
Diffstat (limited to 'imap4d')
-rw-r--r-- | imap4d/rename.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/imap4d/rename.c b/imap4d/rename.c index bca502383..c551d2564 100644 --- a/imap4d/rename.c +++ b/imap4d/rename.c @@ -125,8 +125,8 @@ imap4d_rename (struct imap4d_session *session, if (!newname) return io_completion_response (command, RESP_NO, "Permission denied"); - /* It is an error to attempt to rename from a mailbox name that already - exist. */ + /* It is an error to attempt to rename from a mailbox name that does not + exist or to a mailbox name that already exists. */ if (stat (newname, &newst) == 0) { /* FIXME: What if it's a maildir?!? */ @@ -216,9 +216,26 @@ imap4d_rename (struct imap4d_session *session, } else { - if (rename (oldname, newname) != 0) + rc = mu_rename_file (oldname, newname, 0); + if (rc) { - mu_diag_funcall (MU_DIAG_ERROR, "rename", oldname, errno); + switch (rc) + { + case MU_ERR_REMOVE_SOURCE: + mu_error (_("failed to remove source mailbox after moving %s to %s"), + oldname, newname); + break; + + case MU_ERR_RESTORE_META: + mu_error (_("failed to restore mailbox ownership/modes after moving %s to %s"), + oldname, newname); + break; + + default: + mu_error (_("error renaming mailbox %s to %s: %s"), + oldname, newname, mu_strerror (rc)); + } + rc = RESP_NO; msg = "Failed"; } |