From 205debb6e5882687f43a98fec7bb577173b2fe28 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 16 Nov 2010 18:47:48 +0000 Subject: [PATCH] mbox: Ignore utime()=EPERM failures when trying to set atime back. This happens with shared mboxes when file's owner isn't the process's euid. --- src/lib-storage/index/mbox/mbox-save.c | 6 ++++-- src/lib-storage/index/mbox/mbox-sync.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib-storage/index/mbox/mbox-save.c b/src/lib-storage/index/mbox/mbox-save.c index b69f078a82..df151697bb 100644 --- a/src/lib-storage/index/mbox/mbox-save.c +++ b/src/lib-storage/index/mbox/mbox-save.c @@ -763,12 +763,14 @@ int mbox_transaction_save_commit_pre(struct mail_save_context *_ctx) } if (ret == 0 && ctx->orig_atime != st.st_atime) { - /* try to set atime back to its original value */ + /* try to set atime back to its original value. + (it'll fail with EPERM for shared mailboxes where we aren't + the file's owner) */ struct utimbuf buf; buf.modtime = st.st_mtime; buf.actime = ctx->orig_atime; - if (utime(mbox->box.path, &buf) < 0) + if (utime(mbox->box.path, &buf) < 0 && errno != EPERM) mbox_set_syscall_error(mbox, "utime()"); } diff --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index 88aff6c602..d2c2287f2a 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -1904,7 +1904,9 @@ again: if (ret == 0 && mbox->mbox_fd != -1 && sync_ctx.keep_recent && !readonly) { - /* try to set atime back to its original value */ + /* try to set atime back to its original value. + (it'll fail with EPERM for shared mailboxes where we aren't + the file's owner) */ struct utimbuf buf; struct stat st; @@ -1913,7 +1915,7 @@ again: else { buf.modtime = st.st_mtime; buf.actime = sync_ctx.orig_atime; - if (utime(mbox->box.path, &buf) < 0) + if (utime(mbox->box.path, &buf) < 0 && errno != EPERM) mbox_set_syscall_error(mbox, "utime()"); } } -- 2.47.3