diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index f4ab19f8b7..09f341ffaa 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -3383,6 +3383,12 @@ fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)
 	int			flags;
 	int			returncode;
 
+#ifdef WIN32
+	/* Windows doesn't allow us to open directories at all.
+	*/
+	if (isdir)
+		return 0;
+#endif
 	/*
 	 * Some OSs require directories to be opened read-only whereas other
 	 * systems don't allow us to fsync files opened read-only; so we need both
@@ -3394,17 +3400,12 @@ fsync_fname_ext(const char *fname, bool isdir, bool ignore_perm, int elevel)
 		flags |= O_RDWR;
 	else
 		flags |= O_RDONLY;
-
 	fd = OpenTransientFile(fname, flags);
 
 	/*
-	 * Some OSs don't allow us to open directories at all (Windows returns
-	 * EACCES), just ignore the error in that case.  If desired also silently
-	 * ignoring errors about unreadable files. Log others.
+	 * If desired silently ignore errors about unreadable files. Log others.
 	 */
-	if (fd < 0 && isdir && (errno == EISDIR || errno == EACCES))
-		return 0;
-	else if (fd < 0 && ignore_perm && errno == EACCES)
+	if (fd < 0 && ignore_perm && errno == EACCES)
 		return 0;
 	else if (fd < 0)
 	{
