Commit 0ad6f848 authored by Peter Eisentraut's avatar Peter Eisentraut

Move pg_upgrade's Windows link() implementation to AC_REPLACE_FUNCS

This way we can make use of it in other components as well, and it
fits better with the rest of the build system.

Discussion: https://www.postgresql.org/message-id/flat/72fff73f-dc9c-4ef4-83e8-d2e60c98df48%402ndquadrant.com
parent d6775504
...@@ -15505,6 +15505,19 @@ esac ...@@ -15505,6 +15505,19 @@ esac
fi fi
ac_fn_c_check_func "$LINENO" "link" "ac_cv_func_link"
if test "x$ac_cv_func_link" = xyes; then :
$as_echo "#define HAVE_LINK 1" >>confdefs.h
else
case " $LIBOBJS " in
*" link.$ac_objext "* ) ;;
*) LIBOBJS="$LIBOBJS link.$ac_objext"
;;
esac
fi
ac_fn_c_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp" ac_fn_c_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp"
if test "x$ac_cv_func_mkdtemp" = xyes; then : if test "x$ac_cv_func_mkdtemp" = xyes; then :
$as_echo "#define HAVE_MKDTEMP 1" >>confdefs.h $as_echo "#define HAVE_MKDTEMP 1" >>confdefs.h
......
...@@ -1697,6 +1697,7 @@ AC_REPLACE_FUNCS(m4_normalize([ ...@@ -1697,6 +1697,7 @@ AC_REPLACE_FUNCS(m4_normalize([
getpeereid getpeereid
getrusage getrusage
inet_aton inet_aton
link
mkdtemp mkdtemp
pread pread
pwrite pwrite
......
...@@ -26,10 +26,6 @@ ...@@ -26,10 +26,6 @@
#include "storage/checksum.h" #include "storage/checksum.h"
#include "storage/checksum_impl.h" #include "storage/checksum_impl.h"
#ifdef WIN32
static int win32_pghardlink(const char *src, const char *dst);
#endif
/* /*
* cloneFile() * cloneFile()
...@@ -151,7 +147,7 @@ void ...@@ -151,7 +147,7 @@ void
linkFile(const char *src, const char *dst, linkFile(const char *src, const char *dst,
const char *schemaName, const char *relName) const char *schemaName, const char *relName)
{ {
if (pg_link_file(src, dst) < 0) if (link(src, dst) < 0)
pg_fatal("error while creating link for relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n", pg_fatal("error while creating link for relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
schemaName, relName, src, dst, strerror(errno)); schemaName, relName, src, dst, strerror(errno));
} }
...@@ -369,29 +365,10 @@ check_hard_link(void) ...@@ -369,29 +365,10 @@ check_hard_link(void)
snprintf(new_link_file, sizeof(new_link_file), "%s/PG_VERSION.linktest", new_cluster.pgdata); snprintf(new_link_file, sizeof(new_link_file), "%s/PG_VERSION.linktest", new_cluster.pgdata);
unlink(new_link_file); /* might fail */ unlink(new_link_file); /* might fail */
if (pg_link_file(existing_file, new_link_file) < 0) if (link(existing_file, new_link_file) < 0)
pg_fatal("could not create hard link between old and new data directories: %s\n" pg_fatal("could not create hard link between old and new data directories: %s\n"
"In link mode the old and new data directories must be on the same file system.\n", "In link mode the old and new data directories must be on the same file system.\n",
strerror(errno)); strerror(errno));
unlink(new_link_file); unlink(new_link_file);
} }
#ifdef WIN32
/* implementation of pg_link_file() on Windows */
static int
win32_pghardlink(const char *src, const char *dst)
{
/*
* CreateHardLinkA returns zero for failure
* https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka
*/
if (CreateHardLinkA(dst, src, NULL) == 0)
{
_dosmaperr(GetLastError());
return -1;
}
else
return 0;
}
#endif
...@@ -65,7 +65,6 @@ extern char *output_files[]; ...@@ -65,7 +65,6 @@ extern char *output_files[];
#ifndef WIN32 #ifndef WIN32
#define pg_mv_file rename #define pg_mv_file rename
#define pg_link_file link
#define PATH_SEPARATOR '/' #define PATH_SEPARATOR '/'
#define PATH_QUOTE '\'' #define PATH_QUOTE '\''
#define RM_CMD "rm -f" #define RM_CMD "rm -f"
...@@ -76,7 +75,6 @@ extern char *output_files[]; ...@@ -76,7 +75,6 @@ extern char *output_files[];
#define ECHO_BLANK "" #define ECHO_BLANK ""
#else #else
#define pg_mv_file pgrename #define pg_mv_file pgrename
#define pg_link_file win32_pghardlink
#define PATH_SEPARATOR '\\' #define PATH_SEPARATOR '\\'
#define PATH_QUOTE '"' #define PATH_QUOTE '"'
#define RM_CMD "DEL /q" #define RM_CMD "DEL /q"
......
...@@ -346,6 +346,9 @@ ...@@ -346,6 +346,9 @@
/* Define to 1 if you have the `z' library (-lz). */ /* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ #undef HAVE_LIBZ
/* Define to 1 if you have the `link' function. */
#undef HAVE_LINK
/* Define to 1 if the system has the type `locale_t'. */ /* Define to 1 if the system has the type `locale_t'. */
#undef HAVE_LOCALE_T #undef HAVE_LOCALE_T
......
...@@ -381,6 +381,10 @@ extern float pg_strtof(const char *nptr, char **endptr); ...@@ -381,6 +381,10 @@ extern float pg_strtof(const char *nptr, char **endptr);
#define strtof(a,b) (pg_strtof((a),(b))) #define strtof(a,b) (pg_strtof((a),(b)))
#endif #endif
#ifndef HAVE_LINK
extern int link(const char *src, const char *dst);
#endif
#ifndef HAVE_MKDTEMP #ifndef HAVE_MKDTEMP
extern char *mkdtemp(char *path); extern char *mkdtemp(char *path);
#endif #endif
......
/*-------------------------------------------------------------------------
*
* link.c
*
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
*
* IDENTIFICATION
* src/port/link.c
*
*-------------------------------------------------------------------------
*/
#include "c.h"
#ifdef WIN32
int
link(const char *src, const char *dst)
{
/*
* CreateHardLinkA returns zero for failure
* https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka
*/
if (CreateHardLinkA(dst, src, NULL) == 0)
{
_dosmaperr(GetLastError());
return -1;
}
else
return 0;
}
#endif
...@@ -98,7 +98,7 @@ sub mkvcbuild ...@@ -98,7 +98,7 @@ sub mkvcbuild
chklocale.c explicit_bzero.c fls.c getpeereid.c getrusage.c inet_aton.c random.c chklocale.c explicit_bzero.c fls.c getpeereid.c getrusage.c inet_aton.c random.c
srandom.c getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c srandom.c getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c
erand48.c snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c erand48.c snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
dirent.c dlopen.c getopt.c getopt_long.c dirent.c dlopen.c getopt.c getopt_long.c link.c
pread.c pwrite.c pg_bitutils.c pread.c pwrite.c pg_bitutils.c
pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c
pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c
......
...@@ -298,6 +298,7 @@ sub GenerateFiles ...@@ -298,6 +298,7 @@ sub GenerateFiles
HAVE_LIBXML2 => undef, HAVE_LIBXML2 => undef,
HAVE_LIBXSLT => undef, HAVE_LIBXSLT => undef,
HAVE_LIBZ => $self->{options}->{zlib} ? 1 : undef, HAVE_LIBZ => $self->{options}->{zlib} ? 1 : undef,
HAVE_LINK => undef,
HAVE_LOCALE_T => 1, HAVE_LOCALE_T => 1,
HAVE_LONG_INT_64 => undef, HAVE_LONG_INT_64 => undef,
HAVE_LONG_LONG_INT_64 => 1, HAVE_LONG_LONG_INT_64 => 1,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment