Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9ad14f

Browse files
committed
Use NAMEDATALEN instead of local define.
Modify path separators for Win32. Per ideas from Takahiro Itagaki
1 parent 36d3afd commit e9ad14f

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

contrib/pg_upgrade/exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ check_exec(migratorContext *ctx, const char *dir, const char *cmdName)
138138
char path[MAXPGPATH];
139139
const char *errMsg;
140140

141-
snprintf(path, sizeof(path), "%s%c%s", dir, pathSeparator, cmdName);
141+
snprintf(path, sizeof(path), "%s/%s", dir, cmdName);
142142

143143
if ((errMsg = validate_exec(path)) == NULL)
144144
return 1; /* 1 -> first alternative OK */
@@ -286,8 +286,8 @@ check_data_dir(migratorContext *ctx, const char *pg_data)
286286
{
287287
struct stat statBuf;
288288

289-
snprintf(subDirName, sizeof(subDirName), "%s%c%s", pg_data,
290-
pathSeparator, requiredSubdirs[subdirnum]);
289+
snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
290+
requiredSubdirs[subdirnum]);
291291

292292
if ((stat(subDirName, &statBuf)) != 0)
293293
{

contrib/pg_upgrade/file.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@
1313
#include <windows.h>
1414
#endif
1515

16-
#ifndef WIN32
17-
char pathSeparator = '/';
18-
#else
19-
char pathSeparator = '\\';
20-
#endif
21-
2216

2317
static int copy_file(const char *fromfile, const char *tofile, bool force);
2418

contrib/pg_upgrade/option.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,9 +308,13 @@ validateDirectoryOption(migratorContext *ctx, char **dirpath,
308308
/*
309309
* Trim off any trailing path separators
310310
*/
311-
if ((*dirpath)[strlen(*dirpath) - 1] == pathSeparator)
311+
#ifndef WIN32
312+
if ((*dirpath)[strlen(*dirpath) - 1] == '/')
313+
#else
314+
if ((*dirpath)[strlen(*dirpath) - 1] == '/' ||
315+
(*dirpath)[strlen(*dirpath) - 1] == '\\')
316+
#endif
312317
(*dirpath)[strlen(*dirpath) - 1] = 0;
313-
314318
}
315319

316320

contrib/pg_upgrade/pg_upgrade.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "libpq-fe.h"
1717

1818
/* Allocate for null byte */
19-
#define NAMEDATASIZE (NAMEDATALEN + 1)
20-
2119
#define USER_NAME_SIZE 128
2220

2321
#define MAX_STRING 1024
@@ -73,15 +71,13 @@ extern int pgunlink(const char *path);
7371
extern void copydir(char *fromdir, char *todir, bool recurse);
7472
extern bool rmtree(const char *path, bool rmtopdir);
7573

76-
extern char pathSeparator;
77-
7874
/*
7975
* Each relation is represented by a relinfo structure.
8076
*/
8177
typedef struct
8278
{
83-
char nspname[NAMEDATASIZE]; /* namespace name */
84-
char relname[NAMEDATASIZE]; /* relation name */
79+
char nspname[NAMEDATALEN]; /* namespace name */
80+
char relname[NAMEDATALEN]; /* relation name */
8581
Oid reloid; /* relation oid */
8682
Oid relfilenode; /* relation relfile node */
8783
Oid toastrelid; /* oid of the toast relation */
@@ -103,10 +99,10 @@ typedef struct
10399
Oid new; /* Relfilenode of the new relation */
104100
char old_file[MAXPGPATH];
105101
char new_file[MAXPGPATH];
106-
char old_nspname[NAMEDATASIZE]; /* old name of the namespace */
107-
char old_relname[NAMEDATASIZE]; /* old name of the relation */
108-
char new_nspname[NAMEDATASIZE]; /* new name of the namespace */
109-
char new_relname[NAMEDATASIZE]; /* new name of the relation */
102+
char old_nspname[NAMEDATALEN]; /* old name of the namespace */
103+
char old_relname[NAMEDATALEN]; /* old name of the relation */
104+
char new_nspname[NAMEDATALEN]; /* new name of the namespace */
105+
char new_relname[NAMEDATALEN]; /* new name of the relation */
110106
} FileNameMap;
111107

112108
/*
@@ -115,7 +111,7 @@ typedef struct
115111
typedef struct
116112
{
117113
Oid db_oid; /* oid of the database */
118-
char db_name[NAMEDATASIZE]; /* database name */
114+
char db_name[NAMEDATALEN]; /* database name */
119115
char db_tblspace[MAXPGPATH]; /* database default tablespace path */
120116
RelInfoArr rel_arr; /* array of all user relinfos */
121117
} DbInfo;

contrib/pg_upgrade/version_old_8_3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,8 @@ old_8_3_rebuild_tsvector_tables(migratorContext *ctx, bool check_mode,
318318
{
319319
PGresult *res;
320320
bool db_used = false;
321-
char old_nspname[NAMEDATASIZE] = "",
322-
old_relname[NAMEDATASIZE] = "";
321+
char old_nspname[NAMEDATALEN] = "",
322+
old_relname[NAMEDATALEN] = "";
323323
int ntups;
324324
int rowno;
325325
int i_nspname,

0 commit comments

Comments
 (0)