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

Commit677da8c

Browse files
committed
Use access() to check file existence in GetNewRelFileNode()
Previous code used BasicOpenFile() and close() just to check for a filecollision, while there is no need to hold open a file descriptor butthat's an overkill here.Author: Paul GuoReviewed-by: Peter Eisentraut, Michael PaquierDiscussion:https://postgr.es/m/CABQrizcUtiHaquxK=d4etBX8GF9kbZB50Nt1gO9_aN-e9SptyQ@mail.gmail.com
1 parent0903bbd commit677da8c

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

‎src/backend/catalog/catalog.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
397397
{
398398
RelFileNodeBackendrnode;
399399
char*rpath;
400-
intfd;
401400
boolcollides;
402401
BackendIdbackend;
403402

@@ -445,26 +444,20 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
445444

446445
/* Check for existing file of same name */
447446
rpath=relpath(rnode,MAIN_FORKNUM);
448-
fd=BasicOpenFile(rpath,O_RDONLY |PG_BINARY);
449447

450-
if (fd >=0)
448+
if (access(rpath,F_OK)==0)
451449
{
452450
/* definite collision */
453-
close(fd);
454451
collides= true;
455452
}
456453
else
457454
{
458455
/*
459456
* Here we have a little bit of a dilemma: if errno is something
460457
* other than ENOENT, should we declare a collision and loop? In
461-
* particular one might think this advisable for, say, EPERM.
462-
* However there really shouldn't be any unreadable files in a
463-
* tablespace directory, and if the EPERM is actually complaining
464-
* that we can't read the directory itself, we'd be in an infinite
465-
* loop. In practice it seems best to go ahead regardless of the
466-
* errno. If there is a colliding file we will get an smgr
467-
* failure when we attempt to create the new relation file.
458+
* practice it seems best to go ahead regardless of the errno. If
459+
* there is a colliding file we will get an smgr failure when we
460+
* attempt to create the new relation file.
468461
*/
469462
collides= false;
470463
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp