Skip to content

Commit a6f56ef

Browse files
committed
PG_MAJORVERSION:
For simplicity, use PG_MAJORVERSION rather than PG_VERSION for creation of the PG_VERSION file.
1 parent 9261b19 commit a6f56ef

File tree

2 files changed

+20
-90
lines changed

2 files changed

+20
-90
lines changed

src/backend/commands/tablespace.c

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.67 2010/01/06 01:48:09 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.68 2010/01/06 23:23:51 momjian Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -82,7 +82,7 @@ char *temp_tablespaces = NULL;
8282

8383

8484
static bool remove_tablespace_directories(Oid tablespaceoid, bool redo);
85-
static void set_short_version(const char *path);
85+
static void write_version_file(const char *path);
8686

8787

8888
/*
@@ -332,7 +332,7 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
332332
* (the emptiness check above will fail), and to label tablespace
333333
* directories by PG version.
334334
*/
335-
set_short_version(location);
335+
write_version_file(location);
336336

337337
/*
338338
* All seems well, create the symlink
@@ -673,54 +673,28 @@ remove_tablespace_directories(Oid tablespaceoid, bool redo)
673673
* write out the PG_VERSION file in the specified directory
674674
*/
675675
static void
676-
set_short_version(const char *path)
676+
write_version_file(const char *path)
677677
{
678-
char *short_version;
679-
bool gotdot = false;
680-
int end;
681678
char *fullname;
682679
FILE *version_file;
683680

684-
/* Construct short version string (should match initdb.c) */
685-
short_version = pstrdup(PG_VERSION);
686-
687-
for (end = 0; short_version[end] != '\0'; end++)
688-
{
689-
if (short_version[end] == '.')
690-
{
691-
Assert(end != 0);
692-
if (gotdot)
693-
break;
694-
else
695-
gotdot = true;
696-
}
697-
else if (short_version[end] < '0' || short_version[end] > '9')
698-
{
699-
/* gone past digits and dots */
700-
break;
701-
}
702-
}
703-
Assert(end > 0 && short_version[end - 1] != '.' && gotdot);
704-
short_version[end] = '\0';
705-
706681
/* Now write the file */
707682
fullname = palloc(strlen(path) + 11 + 1);
708683
sprintf(fullname, "%s/PG_VERSION", path);
709-
version_file = AllocateFile(fullname, PG_BINARY_W);
710-
if (version_file == NULL)
684+
685+
if ((version_file = AllocateFile(fullname, PG_BINARY_W)) == NULL)
711686
ereport(ERROR,
712687
(errcode_for_file_access(),
713688
errmsg("could not write to file \"%s\": %m",
714689
fullname)));
715-
fprintf(version_file, "%s\n", short_version);
690+
fprintf(version_file, "%s\n", PG_MAJORVERSION);
716691
if (FreeFile(version_file))
717692
ereport(ERROR,
718693
(errcode_for_file_access(),
719694
errmsg("could not write to file \"%s\": %m",
720695
fullname)));
721696

722697
pfree(fullname);
723-
pfree(short_version);
724698
}
725699

726700
/*
@@ -1370,7 +1344,7 @@ tblspc_redo(XLogRecPtr lsn, XLogRecord *record)
13701344
location)));
13711345

13721346
/* Create or re-create the PG_VERSION file in the target directory */
1373-
set_short_version(location);
1347+
write_version_file(location);
13741348

13751349
/* Create the symlink if not already present */
13761350
linkloc = (char *) palloc(OIDCHARS + OIDCHARS + 1);

src/bin/initdb/initdb.c

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
* Portions taken from FreeBSD.
4444
*
45-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.181 2010/01/02 16:57:58 momjian Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.182 2010/01/06 23:23:51 momjian Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -156,16 +156,15 @@ static int mkdir_p(char *path, mode_t omode);
156156
static void exit_nicely(void);
157157
static char *get_id(void);
158158
static char *get_encoding_id(char *encoding_name);
159-
static char *get_short_version(void);
160159
static int check_data_dir(char *dir);
161160
static bool mkdatadir(const char *subdir);
162161
static void set_input(char **dest, char *filename);
163162
static void check_input(char *path);
164-
static void set_short_version(char *short_version, char *extrapath);
163+
static void write_version_file(char *extrapath);
165164
static void set_null_conf(void);
166165
static void test_config_settings(void);
167166
static void setup_config(void);
168-
static void bootstrap_template1(char *short_version);
167+
static void bootstrap_template1(void);
169168
static void setup_auth(void);
170169
static void get_set_pwd(void);
171170
static void setup_depend(void);
@@ -802,42 +801,6 @@ find_matching_ts_config(const char *lc_type)
802801
}
803802

804803

805-
/*
806-
* get short version of VERSION
807-
*/
808-
static char *
809-
get_short_version(void)
810-
{
811-
bool gotdot = false;
812-
int end;
813-
char *vr;
814-
815-
vr = xstrdup(PG_VERSION);
816-
817-
for (end = 0; vr[end] != '\0'; end++)
818-
{
819-
if (vr[end] == '.')
820-
{
821-
if (end == 0)
822-
return NULL;
823-
else if (gotdot)
824-
break;
825-
else
826-
gotdot = true;
827-
}
828-
else if (vr[end] < '0' || vr[end] > '9')
829-
{
830-
/* gone past digits and dots */
831-
break;
832-
}
833-
}
834-
if (end == 0 || vr[end - 1] == '.' || !gotdot)
835-
return NULL;
836-
837-
vr[end] = '\0';
838-
return vr;
839-
}
840-
841804
/*
842805
* make sure the directory either doesn't exist or is empty
843806
*
@@ -972,7 +935,7 @@ check_input(char *path)
972935
* if extrapath is not NULL
973936
*/
974937
static void
975-
set_short_version(char *short_version, char *extrapath)
938+
write_version_file(char *extrapath)
976939
{
977940
FILE *version_file;
978941
char *path;
@@ -987,14 +950,14 @@ set_short_version(char *short_version, char *extrapath)
987950
path = pg_malloc(strlen(pg_data) + strlen(extrapath) + 13);
988951
sprintf(path, "%s/%s/PG_VERSION", pg_data, extrapath);
989952
}
990-
version_file = fopen(path, PG_BINARY_W);
991-
if (version_file == NULL)
953+
954+
if ((version_file = fopen(path, PG_BINARY_W)) == NULL)
992955
{
993956
fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"),
994957
progname, path, strerror(errno));
995958
exit_nicely();
996959
}
997-
if (fprintf(version_file, "%s\n", short_version) < 0 ||
960+
if (fprintf(version_file, "%s\n", PG_MAJORVERSION) < 0 ||
998961
fclose(version_file))
999962
{
1000963
fprintf(stderr, _("%s: could not write file \"%s\": %s\n"),
@@ -1297,7 +1260,7 @@ setup_config(void)
12971260
* run the BKI script in bootstrap mode to create template1
12981261
*/
12991262
static void
1300-
bootstrap_template1(char *short_version)
1263+
bootstrap_template1(void)
13011264
{
13021265
PG_CMD_DECL;
13031266
char **line;
@@ -1317,7 +1280,7 @@ bootstrap_template1(char *short_version)
13171280
/* Check that bki file appears to be of the right version */
13181281

13191282
snprintf(headerline, sizeof(headerline), "# PostgreSQL %s\n",
1320-
short_version);
1283+
PG_MAJORVERSION);
13211284

13221285
if (strcmp(headerline, *bki_lines) != 0)
13231286
{
@@ -2480,7 +2443,6 @@ main(int argc, char *argv[])
24802443
i,
24812444
ret;
24822445
int option_index;
2483-
char *short_version;
24842446
char *effective_user;
24852447
char *pgdenv; /* PGDATA value gotten from and sent to
24862448
* environment */
@@ -2788,12 +2750,6 @@ main(int argc, char *argv[])
27882750

27892751
canonicalize_path(share_path);
27902752

2791-
if ((short_version = get_short_version()) == NULL)
2792-
{
2793-
fprintf(stderr, _("%s: could not determine valid short version string\n"), progname);
2794-
exit(1);
2795-
}
2796-
27972753
effective_user = get_id();
27982754
if (strlen(username) == 0)
27992755
username = effective_user;
@@ -3123,7 +3079,7 @@ main(int argc, char *argv[])
31233079
check_ok();
31243080

31253081
/* Top level PG_VERSION is checked by bootstrapper, so make it first */
3126-
set_short_version(short_version, NULL);
3082+
write_version_file(NULL);
31273083

31283084
/* Select suitable configuration settings */
31293085
set_null_conf();
@@ -3133,12 +3089,12 @@ main(int argc, char *argv[])
31333089
setup_config();
31343090

31353091
/* Bootstrap template1 */
3136-
bootstrap_template1(short_version);
3092+
bootstrap_template1();
31373093

31383094
/*
31393095
* Make the per-database PG_VERSION for template1 only after init'ing it
31403096
*/
3141-
set_short_version(short_version, "base/1");
3097+
write_version_file("base/1");
31423098

31433099
/* Create the stuff we don't need to use bootstrap mode for */
31443100

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