]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Split up logic in nfs_flush_chown_uid
authorShaun A. Johnson <shaun@linuxmagic.com>
Mon, 13 Aug 2018 23:35:54 +0000 (16:35 -0700)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 10 Sep 2019 07:01:50 +0000 (10:01 +0300)
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

index 9498cb195dc86487dbe97ebb2ee6065b06b353fc..bcbfcd757962d9760b878420b5e295fff852ffd6 100644 (file)
@@ -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__