diff --git a/src/bin/pg_combinebackup/copy_file.c b/src/bin/pg_combinebackup/copy_file.c index 05b3e86bd08..57a7c3a202c 100644 --- a/src/bin/pg_combinebackup/copy_file.c +++ b/src/bin/pg_combinebackup/copy_file.c @@ -13,6 +13,10 @@ #ifdef HAVE_COPYFILE_H #include #endif +#ifdef __linux__ +#include +#include +#endif #include #include #include @@ -214,6 +218,9 @@ copy_file_clone(const char *src, const char *dest, pg_fatal("error while cloning file \"%s\" to \"%s\": %m", src, dest); #elif defined(__linux__) && defined(FICLONE) { + int src_fd; + int dest_fd; + if ((src_fd = open(src, O_RDONLY | PG_BINARY, 0)) < 0) pg_fatal("could not open file \"%s\": %m", src); @@ -228,8 +235,11 @@ copy_file_clone(const char *src, const char *dest, unlink(dest); pg_fatal("error while cloning file \"%s\" to \"%s\": %s", - src, dest); + src, dest, strerror(save_errno)); } + + close(src_fd); + close(dest_fd); } #else pg_fatal("file cloning not supported on this platform"); diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c b/src/bin/pg_combinebackup/pg_combinebackup.c index d8e928862b2..363fae234e9 100644 --- a/src/bin/pg_combinebackup/pg_combinebackup.c +++ b/src/bin/pg_combinebackup/pg_combinebackup.c @@ -16,6 +16,14 @@ #include #include +#ifdef HAVE_COPYFILE_H +#include +#endif +#ifdef __linux__ +#include +#include +#endif + #include "backup_label.h" #include "common/blkreftable.h" #include "common/checksum_helper.h"