Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9486d02

Browse files
committed
Use plain mkdir() not pg_mkdir_p() to create subdirectories of PGDATA.
When we're creating subdirectories of PGDATA during initdb, we know darnwell that the parent directory exists (or should exist) and that the newsubdirectory doesn't (or shouldn't). There is therefore no need to useanything more complicated than mkdir(). Using pg_mkdir_p() just opens usup to unexpected failure modes, such as the one exhibited in bug #13853from Nuri Boardman. It's not very clear why pg_mkdir_p() went wrong there,but it is clear that we didn't need to be trying to create parentdirectories in the first place. We're not even saving any code, as provenby the fact that this patch nets out at minus five lines.Since this is a response to a field bug report, back-patch to all branches.
1 parent74d4009 commit9486d02

File tree

1 file changed

+23
-30
lines changed

1 file changed

+23
-30
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ const char *subdirs[] = {
196196
"pg_snapshots",
197197
"pg_subtrans",
198198
"pg_twophase",
199+
"pg_multixact",
199200
"pg_multixact/members",
200201
"pg_multixact/offsets",
201202
"base",
@@ -229,7 +230,6 @@ static FILE *popen_check(const char *command, const char *mode);
229230
staticvoidexit_nicely(void);
230231
staticchar*get_id(void);
231232
staticchar*get_encoding_id(char*encoding_name);
232-
staticboolmkdatadir(constchar*subdir);
233233
staticvoidset_input(char**dest,char*filename);
234234
staticvoidcheck_input(char*path);
235235
staticvoidwrite_version_file(char*extrapath);
@@ -955,32 +955,6 @@ find_matching_ts_config(const char *lc_type)
955955
}
956956

957957

958-
/*
959-
* make the data directory (or one of its subdirectories if subdir is not NULL)
960-
*/
961-
staticbool
962-
mkdatadir(constchar*subdir)
963-
{
964-
char*path;
965-
966-
path=pg_malloc(strlen(pg_data)+2+
967-
(subdir==NULL ?0 :strlen(subdir)));
968-
969-
if (subdir!=NULL)
970-
sprintf(path,"%s/%s",pg_data,subdir);
971-
else
972-
strcpy(path,pg_data);
973-
974-
if (pg_mkdir_p(path,S_IRWXU)==0)
975-
return true;
976-
977-
fprintf(stderr,_("%s: could not create directory \"%s\": %s\n"),
978-
progname,path,strerror(errno));
979-
980-
return false;
981-
}
982-
983-
984958
/*
985959
* set name of given input file variable under data directory
986960
*/
@@ -3220,8 +3194,12 @@ create_data_directory(void)
32203194
pg_data);
32213195
fflush(stdout);
32223196

3223-
if (!mkdatadir(NULL))
3197+
if (pg_mkdir_p(pg_data,S_IRWXU)!=0)
3198+
{
3199+
fprintf(stderr,_("%s: could not create directory \"%s\": %s\n"),
3200+
progname,pg_data,strerror(errno));
32243201
exit_nicely();
3202+
}
32253203
else
32263204
check_ok();
32273205

@@ -3403,10 +3381,25 @@ initialize_data_directory(void)
34033381
printf(_("creating subdirectories ... "));
34043382
fflush(stdout);
34053383

3406-
for (i=0;i<(sizeof(subdirs) /sizeof(char*));i++)
3384+
for (i=0;i<lengthof(subdirs);i++)
34073385
{
3408-
if (!mkdatadir(subdirs[i]))
3386+
char*path;
3387+
3388+
path=pg_malloc(strlen(pg_data)+strlen(subdirs[i])+2);
3389+
sprintf(path,"%s/%s",pg_data,subdirs[i]);
3390+
3391+
/*
3392+
* The parent directory already exists, so we only need mkdir() not
3393+
* pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
3394+
*/
3395+
if (mkdir(path,S_IRWXU)<0)
3396+
{
3397+
fprintf(stderr,_("%s: could not create directory \"%s\": %s\n"),
3398+
progname,path,strerror(errno));
34093399
exit_nicely();
3400+
}
3401+
3402+
free(path);
34103403
}
34113404

34123405
check_ok();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp