Skip to content

Commit d5ce481

Browse files
committed
add windows support
1 parent ca99703 commit d5ce481

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

src/bin/pg_dump/pg_backup.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@ typedef struct RelFileMap
306306
Oid reltoastrelid;
307307
} RelFileMap;
308308

309+
#ifndef WIN32
310+
#define pg_link_file link
311+
#else
312+
#define pg_link_file win32_pghardlink
313+
#endif
314+
309315
extern RelFileMap* fillRelFileMap(Archive* fout, int* nrels, int* ntoastrels,
310316
const char* dbname, const char* tblname);
311317
extern RelFileMap* fillRelFileMapSeq(Archive *fout, int *nrels,

src/bin/pg_dump/pg_backup_db.c

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ fillRelFileMapSeq(Archive *fout, int *nrels,
933933
int i_tablespace;
934934
int i_data_directory;
935935
int i_tablespace_location;
936-
int i_relpersistence;
937936
const char *data_directory;
938937
Oid dboid;
939938
int i;
@@ -991,7 +990,6 @@ fillRelFileMapSeq(Archive *fout, int *nrels,
991990
i_relname = PQfnumber(res, "relname");
992991
i_tablespace = PQfnumber(res, "reltablespace");
993992
i_tablespace_location = PQfnumber(res, "pg_tablespace_location");
994-
i_relpersistence = PQfnumber(res, "relpersistence");
995993
map = pg_malloc(sizeof(RelFileMap) * ntups);
996994

997995
for (i = 0; i < ntups; i++)
@@ -1003,10 +1001,6 @@ fillRelFileMapSeq(Archive *fout, int *nrels,
10031001
cur->relfilenode = atooid(PQgetvalue(res, i, i_relfilenode));
10041002
cur->relname = strdup(PQgetvalue(res, i, i_relname));
10051003

1006-
/* 'c' is for RELPERSISTENCE_CONSTANT. */
1007-
// if (*PQgetvalue(res, i, i_relpersistence) != 'c')
1008-
// exit_horribly(NULL, "Cannot transfer non-constant relation '%s' \n", cur->relname);
1009-
10101004
if (atoi(PQgetvalue(res, i, i_tablespace)) == 0)
10111005
{
10121006
cur->datadir = strdup(data_directory);
@@ -1128,6 +1122,7 @@ fillRelFileMapToast(Archive *fout, RelFileMap *map,
11281122
static int
11291123
copy_file(const char *srcfile, const char *dstfile, bool create_file)
11301124
{
1125+
#ifndef WIN32
11311126
#define COPY_BUF_SIZE (50 * BLCKSZ)
11321127

11331128
int src_fd;
@@ -1204,7 +1199,40 @@ copy_file(const char *srcfile, const char *dstfile, bool create_file)
12041199
errno = save_errno;
12051200

12061201
return ret;
1202+
#else /* WIN32 */
1203+
1204+
/* Last argument of Windows CopyFile func is bFailIfExists.
1205+
* If we're asked to create_file, it should not exist. Otherwise, we
1206+
* want to rewrite it.
1207+
*/
1208+
if (CopyFile(src, dst, create_file) == 0)
1209+
{
1210+
_dosmaperr(GetLastError());
1211+
pg_fatal("error while copying relation \"%s.%s\" (\"%s\" to \"%s\"): %s\n",
1212+
schemaName, relName, src, dst, strerror(errno));
1213+
}
1214+
1215+
#endif /* WIN32 */
1216+
}
1217+
1218+
#ifdef WIN32
1219+
/* implementation of pg_link_file() on Windows */
1220+
static int
1221+
win32_pghardlink(const char *src, const char *dst)
1222+
{
1223+
/*
1224+
* CreateHardLinkA returns zero for failure
1225+
* http://msdn.microsoft.com/en-us/library/aa363860(VS.85).aspx
1226+
*/
1227+
if (CreateHardLinkA(dst, src, NULL) == 0)
1228+
{
1229+
_dosmaperr(GetLastError());
1230+
return -1;
1231+
}
1232+
else
1233+
return 0;
12071234
}
1235+
#endif
12081236

12091237
/*
12101238
* Transfer relation fork, specified by type_suffix, to transfer subdir.
@@ -1306,12 +1334,11 @@ transfer_relfile(RelFileMap *map, const char *type_suffix,
13061334
}
13071335
else
13081336
{
1309-
if (link(db_file, transfer_file) != 0)
1337+
if (pg_link_file(db_file, transfer_file) != 0)
13101338
{
13111339
exit_horribly(NULL, "cannot dump file (link mode) %s to %s : %s \n",
13121340
db_file, transfer_file, strerror(errno));
13131341
}
1314-
13151342
}
13161343
}
13171344
else
@@ -1354,7 +1381,6 @@ transferCheckControlData(Archive *fout, const char *transfer_dir, bool isRestore
13541381
PQExpBuffer q = createPQExpBuffer();
13551382
PGresult *res;
13561383
const char *serverInfo;
1357-
size_t serverInfoLen = 0;
13581384

13591385
appendPQExpBuffer(q, "SELECT pg_control_init();");
13601386
res = ExecuteSqlQueryForSingleRow(fout, q->data);

src/bin/pg_dump/pg_dump.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18092,7 +18092,6 @@ dumpStatistic(Archive* fout, DumpOptions* dopt, TableInfo *tbinfo)
1809218092
int nfields;
1809318093
int field;
1809418094
int i_starelid;
18095-
int i_staattnum;
1809618095

1809718096
/* Make sure we are in proper schema */
1809818097
selectSourceSchema(fout, "pg_catalog");
@@ -18148,7 +18147,6 @@ dumpStatistic(Archive* fout, DumpOptions* dopt, TableInfo *tbinfo)
1814818147
nfields = PQnfields(res);
1814918148

1815018149
i_starelid = PQfnumber(res, "starelid");
18151-
i_staattnum = PQfnumber(res, "staattnum");
1815218150

1815318151
for (tuple = 0; tuple < PQntuples(res); tuple++)
1815418152
{

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