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

Commit8ca03aa

Browse files
committed
pg_dump: Simplify mkdir() error checking
mkdir() can check for errors itself. We don't need to code thatourselves again.
1 parentf5bcd39 commit8ca03aa

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

‎src/bin/pg_dump/pg_backup_directory.c

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
8484

8585
staticchar*prependDirectory(ArchiveHandle*AH,constchar*relativeFilename);
8686

87-
staticvoidcreateDirectory(constchar*dir);
88-
8987

9088
/*
9189
*Init routine required by ALL formats. This is a global routine
@@ -148,8 +146,9 @@ InitArchiveFmt_Directory(ArchiveHandle *AH)
148146

149147
if (AH->mode==archModeWrite)
150148
{
151-
/* Create the directory, errors are caught there */
152-
createDirectory(ctx->directory);
149+
if (mkdir(ctx->directory,0700)<0)
150+
exit_horribly(modulename,"could not create directory \"%s\": %s\n",
151+
ctx->directory,strerror(errno));
153152
}
154153
else
155154
{/* Read Mode */
@@ -628,34 +627,6 @@ _EndBlobs(ArchiveHandle *AH, TocEntry *te)
628627
ctx->blobsTocFH=NULL;
629628
}
630629

631-
staticvoid
632-
createDirectory(constchar*dir)
633-
{
634-
structstatst;
635-
636-
/* the directory must not exist yet. */
637-
if (stat(dir,&st)==0)
638-
{
639-
if (S_ISDIR(st.st_mode))
640-
exit_horribly(modulename,
641-
"cannot create directory %s, it exists already\n",
642-
dir);
643-
else
644-
exit_horribly(modulename,
645-
"cannot create directory %s, a file with this name "
646-
"exists already\n",dir);
647-
}
648-
649-
/*
650-
* Now we create the directory. Note that for some race condition we could
651-
* also run into the situation that the directory has been created just
652-
* between our two calls.
653-
*/
654-
if (mkdir(dir,0700)<0)
655-
exit_horribly(modulename,"could not create directory %s: %s\n",
656-
dir,strerror(errno));
657-
}
658-
659630

660631
staticchar*
661632
prependDirectory(ArchiveHandle*AH,constchar*relativeFilename)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp