*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.67 2010/01/06 01:48:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.68 2010/01/06 23:23:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
static bool remove_tablespace_directories(Oid tablespaceoid, bool redo);
-static void set_short_version(const char *path);
+static void write_version_file(const char *path);
/*
* (the emptiness check above will fail), and to label tablespace
* directories by PG version.
*/
- set_short_version(location);
+ write_version_file(location);
/*
* All seems well, create the symlink
* write out the PG_VERSION file in the specified directory
*/
static void
-set_short_version(const char *path)
+write_version_file(const char *path)
{
- char *short_version;
- bool gotdot = false;
- int end;
char *fullname;
FILE *version_file;
- /* Construct short version string (should match initdb.c) */
- short_version = pstrdup(PG_VERSION);
-
- for (end = 0; short_version[end] != '\0'; end++)
- {
- if (short_version[end] == '.')
- {
- Assert(end != 0);
- if (gotdot)
- break;
- else
- gotdot = true;
- }
- else if (short_version[end] < '0' || short_version[end] > '9')
- {
- /* gone past digits and dots */
- break;
- }
- }
- Assert(end > 0 && short_version[end - 1] != '.' && gotdot);
- short_version[end] = '\0';
-
/* Now write the file */
fullname = palloc(strlen(path) + 11 + 1);
sprintf(fullname, "%s/PG_VERSION", path);
- version_file = AllocateFile(fullname, PG_BINARY_W);
- if (version_file == NULL)
+
+ if ((version_file = AllocateFile(fullname, PG_BINARY_W)) == NULL)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not write to file \"%s\": %m",
fullname)));
- fprintf(version_file, "%s\n", short_version);
+ fprintf(version_file, "%s\n", PG_MAJORVERSION);
if (FreeFile(version_file))
ereport(ERROR,
(errcode_for_file_access(),
fullname)));
pfree(fullname);
- pfree(short_version);
}
/*
location)));
/* Create or re-create the PG_VERSION file in the target directory */
- set_short_version(location);
+ write_version_file(location);
/* Create the symlink if not already present */
linkloc = (char *) palloc(OIDCHARS + OIDCHARS + 1);
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.181 2010/01/02 16:57:58 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.182 2010/01/06 23:23:51 momjian Exp $
*
*-------------------------------------------------------------------------
*/
static void exit_nicely(void);
static char *get_id(void);
static char *get_encoding_id(char *encoding_name);
-static char *get_short_version(void);
static int check_data_dir(char *dir);
static bool mkdatadir(const char *subdir);
static void set_input(char **dest, char *filename);
static void check_input(char *path);
-static void set_short_version(char *short_version, char *extrapath);
+static void write_version_file(char *extrapath);
static void set_null_conf(void);
static void test_config_settings(void);
static void setup_config(void);
-static void bootstrap_template1(char *short_version);
+static void bootstrap_template1(void);
static void setup_auth(void);
static void get_set_pwd(void);
static void setup_depend(void);
}
-/*
- * get short version of VERSION
- */
-static char *
-get_short_version(void)
-{
- bool gotdot = false;
- int end;
- char *vr;
-
- vr = xstrdup(PG_VERSION);
-
- for (end = 0; vr[end] != '\0'; end++)
- {
- if (vr[end] == '.')
- {
- if (end == 0)
- return NULL;
- else if (gotdot)
- break;
- else
- gotdot = true;
- }
- else if (vr[end] < '0' || vr[end] > '9')
- {
- /* gone past digits and dots */
- break;
- }
- }
- if (end == 0 || vr[end - 1] == '.' || !gotdot)
- return NULL;
-
- vr[end] = '\0';
- return vr;
-}
-
/*
* make sure the directory either doesn't exist or is empty
*
* if extrapath is not NULL
*/
static void
-set_short_version(char *short_version, char *extrapath)
+write_version_file(char *extrapath)
{
FILE *version_file;
char *path;
path = pg_malloc(strlen(pg_data) + strlen(extrapath) + 13);
sprintf(path, "%s/%s/PG_VERSION", pg_data, extrapath);
}
- version_file = fopen(path, PG_BINARY_W);
- if (version_file == NULL)
+
+ if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
{
fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
progname, path, strerror(errno));
exit_nicely();
}
- if (fprintf(version_file, "%s\n", short_version) < 0 ||
+ if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
fclose(version_file))
{
fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
* run the BKI script in bootstrap mode to create template1
*/
static void
-bootstrap_template1(char *short_version)
+bootstrap_template1(void)
{
PG_CMD_DECL;
char **line;
/* Check that bki file appears to be of the right version */
snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
- short_version);
+ PG_MAJORVERSION);
if (strcmp(headerline, *bki_lines) != 0)
{
i,
ret;
int option_index;
- char *short_version;
char *effective_user;
char *pgdenv; /* PGDATA value gotten from and sent to
* environment */
canonicalize_path(share_path);
- if ((short_version = get_short_version()) == NULL)
- {
- fprintf(stderr, _("%s: could not determine valid short version string\n"), progname);
- exit(1);
- }
-
effective_user = get_id();
if (strlen(username) == 0)
username = effective_user;
check_ok();
/* Top level PG_VERSION is checked by bootstrapper, so make it first */
- set_short_version(short_version, NULL);
+ write_version_file(NULL);
/* Select suitable configuration settings */
set_null_conf();
setup_config();
/* Bootstrap template1 */
- bootstrap_template1(short_version);
+ bootstrap_template1();
/*
* Make the per-database PG_VERSION for template1 only after init'ing it
*/
- set_short_version(short_version, "base/1");
+ write_version_file("base/1");
/* Create the stuff we don't need to use bootstrap mode for */