From 250992e47275bb6df12b8d3570820bf3e97e6b15 Mon Sep 17 00:00:00 2001 From: "Shaun A. Johnson" Date: Mon, 13 Aug 2018 16:35:54 -0700 Subject: [PATCH] lib: Split up logic in nfs_flush_chown_uid This splits up the logic of nfs_flush_chown_uid() so that there is an individual chown call for each platform instead of a single call that is compiled for both platforms. This is the first step to adjusting how nfs attributes are flushed on Linux because of an issue with chown resetting permissions on the files. --- src/lib/nfs-workarounds.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/nfs-workarounds.c b/src/lib/nfs-workarounds.c index 9498cb195d..bcbfcd7579 100644 --- a/src/lib/nfs-workarounds.c +++ b/src/lib/nfs-workarounds.c @@ -150,6 +150,17 @@ static void nfs_flush_chown_uid(const char *path) #ifdef ATTRCACHE_FLUSH_CHOWN_UID_1 uid = (uid_t)-1; + if (chown(path, uid, (gid_t)-1) < 0) { + if (errno == ESTALE || errno == EPERM || errno == ENOENT) { + /* attr cache is flushed */ + return; + } + if (likely(errno == ENOENT)) { + nfs_flush_file_handle_cache_parent_dir(path); + return; + } + i_error("nfs_flush_chown_uid: chown(%s) failed: %m", path); + } #else struct stat st; @@ -167,7 +178,6 @@ static void nfs_flush_chown_uid(const char *path) i_error("nfs_flush_chown_uid: stat(%s) failed: %m", path); return; } -#endif if (chown(path, uid, (gid_t)-1) < 0) { if (errno == ESTALE || errno == EPERM || errno == ENOENT) { /* attr cache is flushed */ @@ -179,6 +189,7 @@ static void nfs_flush_chown_uid(const char *path) } i_error("nfs_flush_chown_uid: chown(%s) failed: %m", path); } +#endif } #ifdef __FreeBSD__ -- 2.47.3