Skip to content

Commit 0ad6f84

Browse files
committed
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
1 parent d677550 commit 0ad6f84

File tree

9 files changed

+60
-28
lines changed

9 files changed

+60
-28
lines changed

configure

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15505,6 +15505,19 @@ esac
1550515505

1550615506
fi
1550715507

15508+
ac_fn_c_check_func "$LINENO" "link" "ac_cv_func_link"
15509+
if test "x$ac_cv_func_link" = xyes; then :
15510+
$as_echo "#define HAVE_LINK 1" >>confdefs.h
15511+
15512+
else
15513+
case " $LIBOBJS " in
15514+
*" link.$ac_objext "* ) ;;
15515+
*) LIBOBJS="$LIBOBJS link.$ac_objext"
15516+
;;
15517+
esac
15518+
15519+
fi
15520+
1550815521
ac_fn_c_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp"
1550915522
if test "x$ac_cv_func_mkdtemp" = xyes; then :
1551015523
$as_echo "#define HAVE_MKDTEMP 1" >>confdefs.h

configure.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,6 +1697,7 @@ AC_REPLACE_FUNCS(m4_normalize([
16971697
getpeereid
16981698
getrusage
16991699
inet_aton
1700+
link
17001701
mkdtemp
17011702
pread
17021703
pwrite

src/bin/pg_upgrade/file.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
#include "storage/checksum.h"
2727
#include "storage/checksum_impl.h"
2828

29-
#ifdef WIN32
30-
static int win32_pghardlink(const char *src, const char *dst);
31-
#endif
32-
3329

3430
/*
3531
* cloneFile()
@@ -151,7 +147,7 @@ void
151147
linkFile(const char *src, const char *dst,
152148
const char *schemaName, const char *relName)
153149
{
154-
if (pg_link_file(src, dst) < 0)
150+
if (link(src, dst) < 0)
155151
pg_fatal("error while creating link for relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
156152
schemaName, relName, src, dst, strerror(errno));
157153
}
@@ -369,29 +365,10 @@ check_hard_link(void)
369365
snprintf(new_link_file, sizeof(new_link_file), "%s/PG_VERSION.linktest", new_cluster.pgdata);
370366
unlink(new_link_file); /* might fail */
371367

372-
if (pg_link_file(existing_file, new_link_file) < 0)
368+
if (link(existing_file, new_link_file) < 0)
373369
pg_fatal("could not create hard link between old and new data directories: %s\n"
374370
"In link mode the old and new data directories must be on the same file system.\n",
375371
strerror(errno));
376372

377373
unlink(new_link_file);
378374
}
379-
380-
#ifdef WIN32
381-
/* implementation of pg_link_file() on Windows */
382-
static int
383-
win32_pghardlink(const char *src, const char *dst)
384-
{
385-
/*
386-
* CreateHardLinkA returns zero for failure
387-
* https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka
388-
*/
389-
if (CreateHardLinkA(dst, src, NULL) == 0)
390-
{
391-
_dosmaperr(GetLastError());
392-
return -1;
393-
}
394-
else
395-
return 0;
396-
}
397-
#endif

src/bin/pg_upgrade/pg_upgrade.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ extern char *output_files[];
6565

6666
#ifndef WIN32
6767
#define pg_mv_file rename
68-
#define pg_link_file link
6968
#define PATH_SEPARATOR '/'
7069
#define PATH_QUOTE '\''
7170
#define RM_CMD "rm -f"
@@ -76,7 +75,6 @@ extern char *output_files[];
7675
#define ECHO_BLANK ""
7776
#else
7877
#define pg_mv_file pgrename
79-
#define pg_link_file win32_pghardlink
8078
#define PATH_SEPARATOR '\\'
8179
#define PATH_QUOTE '"'
8280
#define RM_CMD "DEL /q"

src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@
346346
/* Define to 1 if you have the `z' library (-lz). */
347347
#undef HAVE_LIBZ
348348

349+
/* Define to 1 if you have the `link' function. */
350+
#undef HAVE_LINK
351+
349352
/* Define to 1 if the system has the type `locale_t'. */
350353
#undef HAVE_LOCALE_T
351354

src/include/port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ extern float pg_strtof(const char *nptr, char **endptr);
381381
#define strtof(a,b) (pg_strtof((a),(b)))
382382
#endif
383383

384+
#ifndef HAVE_LINK
385+
extern int link(const char *src, const char *dst);
386+
#endif
387+
384388
#ifndef HAVE_MKDTEMP
385389
extern char *mkdtemp(char *path);
386390
#endif

src/port/link.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* link.c
4+
*
5+
* Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
6+
* Portions Copyright (c) 1994, Regents of the University of California
7+
*
8+
*
9+
* IDENTIFICATION
10+
* src/port/link.c
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
15+
#include "c.h"
16+
17+
#ifdef WIN32
18+
19+
int
20+
link(const char *src, const char *dst)
21+
{
22+
/*
23+
* CreateHardLinkA returns zero for failure
24+
* https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createhardlinka
25+
*/
26+
if (CreateHardLinkA(dst, src, NULL) == 0)
27+
{
28+
_dosmaperr(GetLastError());
29+
return -1;
30+
}
31+
else
32+
return 0;
33+
}
34+
35+
#endif

src/tools/msvc/Mkvcbuild.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ sub mkvcbuild
9898
chklocale.c explicit_bzero.c fls.c getpeereid.c getrusage.c inet_aton.c random.c
9999
srandom.c getaddrinfo.c gettimeofday.c inet_net_ntop.c kill.c open.c
100100
erand48.c snprintf.c strlcat.c strlcpy.c dirmod.c noblock.c path.c
101-
dirent.c dlopen.c getopt.c getopt_long.c
101+
dirent.c dlopen.c getopt.c getopt_long.c link.c
102102
pread.c pwrite.c pg_bitutils.c
103103
pg_strong_random.c pgcheckdir.c pgmkdirp.c pgsleep.c pgstrcasecmp.c
104104
pqsignal.c mkdtemp.c qsort.c qsort_arg.c quotes.c system.c

src/tools/msvc/Solution.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ sub GenerateFiles
298298
HAVE_LIBXML2 => undef,
299299
HAVE_LIBXSLT => undef,
300300
HAVE_LIBZ => $self->{options}->{zlib} ? 1 : undef,
301+
HAVE_LINK => undef,
301302
HAVE_LOCALE_T => 1,
302303
HAVE_LONG_INT_64 => undef,
303304
HAVE_LONG_LONG_INT_64 => 1,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy