win32_pending_delete_v2.patch

text/x-patch

Filename: win32_pending_delete_v2.patch
Type: text/x-patch
Part: 0
Message: Re: BUG #14243: pg_basebackup failes by a STATUS_DELETE_PENDING file

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
Series: patch v2
File+
src/port/dirmod.c 15 0
src/port/win32error.c 3 0
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index fe2b815..7a52898 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -372,7 +372,22 @@ pgwin32_safestat(const char *path, struct stat * buf)
 
 	r = stat(path, buf);
 	if (r < 0)
+	{
+		if (GetLastError() == ERROR_DELETE_PENDING)
+		{
+			/*
+			 * File has been deleted, but is not gone from the filesystem
+			 * yet. This can happen when some process with FILE_SHARE_DELETE
+			 * has it open and it will be fully removed once that handle
+			 * is closed. Meanwhile, we can't open it, so indicate that
+			 * the file just doesn't exist.
+			 */
+			errno = ENOENT;
+			return -1;
+		}
+
 		return r;
+	}
 
 	if (!GetFileAttributesEx(path, GetFileExInfoStandard, &attr))
 	{
diff --git a/src/port/win32error.c b/src/port/win32error.c
index cf65225..a69d405 100644
--- a/src/port/win32error.c
+++ b/src/port/win32error.c
@@ -161,6 +161,9 @@ static const struct
 	},
 	{
 		ERROR_NOT_ENOUGH_QUOTA, ENOMEM
+	},
+	{
+		ERROR_DELETE_PENDING, ENOENT
 	}
 };