mirror of
https://github.com/postgres/postgres.git
synced 2025-04-21 12:05:57 +03:00
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 6b711cf37c228749b6a8cef50e16e3c587d18dd4, so 9.2 and before are OK.
This commit is contained in:
parent
ea2bb1b47d
commit
8ca75671bd
@ -136,16 +136,22 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
|
|||||||
int save_errno = 0;
|
int save_errno = 0;
|
||||||
|
|
||||||
if ((srcfile == NULL) || (dstfile == NULL))
|
if ((srcfile == NULL) || (dstfile == NULL))
|
||||||
|
{
|
||||||
|
errno = EINVAL;
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((src_fd = open(srcfile, O_RDONLY, 0)) < 0)
|
if ((src_fd = open(srcfile, O_RDONLY, 0)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((dest_fd = open(dstfile, O_RDWR | O_CREAT | (force ? 0 : O_EXCL), S_IRUSR | S_IWUSR)) < 0)
|
if ((dest_fd = open(dstfile, O_RDWR | O_CREAT | (force ? 0 : O_EXCL), S_IRUSR | S_IWUSR)) < 0)
|
||||||
{
|
{
|
||||||
|
save_errno = errno;
|
||||||
|
|
||||||
if (src_fd != 0)
|
if (src_fd != 0)
|
||||||
close(src_fd);
|
close(src_fd);
|
||||||
|
|
||||||
|
errno = save_errno;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,6 +176,9 @@ copy_file(const char *srcfile, const char *dstfile, bool force)
|
|||||||
|
|
||||||
if (write(dest_fd, buffer, nbytes) != nbytes)
|
if (write(dest_fd, buffer, nbytes) != nbytes)
|
||||||
{
|
{
|
||||||
|
/* if write didn't set errno, assume problem is no disk space */
|
||||||
|
if (errno == 0)
|
||||||
|
errno = ENOSPC;
|
||||||
save_errno = errno;
|
save_errno = errno;
|
||||||
ret = -1;
|
ret = -1;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user