8000 pg_upgrade: Report full disk better · imace/postgres@bd5a9a5 · GitHub
[go: up one dir, main page]

Skip to content

Commit bd5a9a5

Browse files
committed
pg_upgrade: Report full disk better
Previously, pg_upgrade would abort copy_file() on a short write without setting errno, which the caller would report as an error with the message "Success". We assume ENOSPC in that case, as we do elsewhere in the code. Also set errno in some other error cases in copy_file() to avoid bogus "Success" error messages. This was broken in 6b711cf, so 9.2 and before are OK.
1 parent 0dbf9a6 commit bd5a9a5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

contrib/pg_upgrade/file.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,22 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
136136
int save_errno = 0;
10234 137137

138138
if ((srcfile == NULL) || (dstfile == NULL))
139+
{
140+
errno = EINVAL;
139141
return -1;
142+
}
140143

141144
if ((src_fd = open(srcfile, O_RDONLY, 0)) < 0)
142145
return -1;
143146

144147
if ((dest_fd = open(dstfile, O_RDWR | O_CREAT | (force ? 0 : O_EXCL), S_IRUSR | S_IWUSR)) < 0)
145148
{
149+
save_errno = errno;
150+
146151
if (src_fd != 0)
147152
close(src_fd);
148153

154+
errno = save_errno;
149155
return -1;
150156
}
151157

@@ -170,6 +176,9 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
170176

171177
if (write(dest_fd, buffer, nbytes) != nbytes)
172178
{
179+
/* if write didn't set errno, assume problem is no disk space */
180+
if (errno == 0)
181+
errno = ENOSPC;
173182
save_errno = errno;
174183
ret = -1;
175184
break;

0 commit comments

Comments
 (0)
0