Use NAMEDATALEN instead of local define.

Modify path separators for Win32.

Per ideas from Takahiro Itagaki
This commit is contained in:
Bruce Momjian 2010-05-14 00:13:38 +00:00
parent 36d3afd2d4
commit e9ad14f9f4
5 changed files with 18 additions and 24 deletions

View File

@ -138,7 +138,7 @@ check_exec(migratorContext *ctx, const char *dir, const char *cmdName)
char path[MAXPGPATH]; char path[MAXPGPATH];
const char *errMsg; const char *errMsg;
snprintf(path, sizeof(path), "%s%c%s", dir, pathSeparator, cmdName); snprintf(path, sizeof(path), "%s/%s", dir, cmdName);
if ((errMsg = validate_exec(path)) == NULL) if ((errMsg = validate_exec(path)) == NULL)
return 1; /* 1 -> first alternative OK */ return 1; /* 1 -> first alternative OK */
@ -286,8 +286,8 @@ check_data_dir(migratorContext *ctx, const char *pg_data)
{ {
struct stat statBuf; struct stat statBuf;
snprintf(subDirName, sizeof(subDirName), "%s%c%s", pg_data, snprintf(subDirName, sizeof(subDirName), "%s/%s", pg_data,
pathSeparator, requiredSubdirs[subdirnum]); requiredSubdirs[subdirnum]);
if ((stat(subDirName, &statBuf)) != 0) if ((stat(subDirName, &statBuf)) != 0)
{ {

View File

@ -13,12 +13,6 @@
#include <windows.h> #include <windows.h>
#endif #endif
#ifndef WIN32
char pathSeparator = '/';
#else
char pathSeparator = '\\';
#endif
static int copy_file(const char *fromfile, const char *tofile, bool force); static int copy_file(const char *fromfile, const char *tofile, bool force);

View File

@ -308,9 +308,13 @@ validateDirectoryOption(migratorContext *ctx, char **dirpath,
/* /*
* Trim off any trailing path separators * Trim off any trailing path separators
*/ */
if ((*dirpath)[strlen(*dirpath) - 1] == pathSeparator) #ifndef WIN32
if ((*dirpath)[strlen(*dirpath) - 1] == '/')
#else
if ((*dirpath)[strlen(*dirpath) - 1] == '/' ||
(*dirpath)[strlen(*dirpath) - 1] == '\\')
#endif
(*dirpath)[strlen(*dirpath) - 1] = 0; (*dirpath)[strlen(*dirpath) - 1] = 0;
} }

View File

@ -16,8 +16,6 @@
#include "libpq-fe.h" #include "libpq-fe.h"
/* Allocate for null byte */ /* Allocate for null byte */
#define NAMEDATASIZE (NAMEDATALEN + 1)
#define USER_NAME_SIZE 128 #define USER_NAME_SIZE 128
#define MAX_STRING 1024 #define MAX_STRING 1024
@ -73,15 +71,13 @@ extern int pgunlink(const char *path);
extern void copydir(char *fromdir, char *todir, bool recurse); extern void copydir(char *fromdir, char *todir, bool recurse);
extern bool rmtree(const char *path, bool rmtopdir); extern bool rmtree(const char *path, bool rmtopdir);
extern char pathSeparator;
/* /*
* Each relation is represented by a relinfo structure. * Each relation is represented by a relinfo structure.
*/ */
typedef struct typedef struct
{ {
char nspname[NAMEDATASIZE]; /* namespace name */ char nspname[NAMEDATALEN]; /* namespace name */
char relname[NAMEDATASIZE]; /* relation name */ char relname[NAMEDATALEN]; /* relation name */
Oid reloid; /* relation oid */ Oid reloid; /* relation oid */
Oid relfilenode; /* relation relfile node */ Oid relfilenode; /* relation relfile node */
Oid toastrelid; /* oid of the toast relation */ Oid toastrelid; /* oid of the toast relation */
@ -103,10 +99,10 @@ typedef struct
Oid new; /* Relfilenode of the new relation */ Oid new; /* Relfilenode of the new relation */
char old_file[MAXPGPATH]; char old_file[MAXPGPATH];
char new_file[MAXPGPATH]; char new_file[MAXPGPATH];
char old_nspname[NAMEDATASIZE]; /* old name of the namespace */ char old_nspname[NAMEDATALEN]; /* old name of the namespace */
char old_relname[NAMEDATASIZE]; /* old name of the relation */ char old_relname[NAMEDATALEN]; /* old name of the relation */
char new_nspname[NAMEDATASIZE]; /* new name of the namespace */ char new_nspname[NAMEDATALEN]; /* new name of the namespace */
char new_relname[NAMEDATASIZE]; /* new name of the relation */ char new_relname[NAMEDATALEN]; /* new name of the relation */
} FileNameMap; } FileNameMap;
/* /*
@ -115,7 +111,7 @@ typedef struct
typedef struct typedef struct
{ {
Oid db_oid; /* oid of the database */ Oid db_oid; /* oid of the database */
char db_name[NAMEDATASIZE]; /* database name */ char db_name[NAMEDATALEN]; /* database name */
char db_tblspace[MAXPGPATH]; /* database default tablespace path */ char db_tblspace[MAXPGPATH]; /* database default tablespace path */
RelInfoArr rel_arr; /* array of all user relinfos */ RelInfoArr rel_arr; /* array of all user relinfos */
} DbInfo; } DbInfo;

View File

@ -318,8 +318,8 @@ old_8_3_rebuild_tsvector_tables(migratorContext *ctx, bool check_mode,
{ {
PGresult *res; PGresult *res;
bool db_used = false; bool db_used = false;
char old_nspname[NAMEDATASIZE] = "", char old_nspname[NAMEDATALEN] = "",
old_relname[NAMEDATASIZE] = ""; old_relname[NAMEDATALEN] = "";
int ntups; int ntups;
int rowno; int rowno;
int i_nspname, int i_nspname,