Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 677da8c

Browse files
committed
Use access() to check file existence in GetNewRelFileNode()
Previous code used BasicOpenFile() and close() just to check for a file collision, while there is no need to hold open a file descriptor but that's an overkill here. Author: Paul Guo Reviewed-by: Peter Eisentraut, Michael Paquier Discussion: https://postgr.es/m/CABQrizcUtiHaquxK=d4etBX8GF9kbZB50Nt1gO9_aN-e9SptyQ@mail.gmail.com
1 parent 0903bbd commit 677da8c

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/backend/catalog/catalog.c

+4-11
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
397397
{
398398
RelFileNodeBackend rnode;
399399
char *rpath;
400-
int fd;
401400
bool collides;
402401
BackendId backend;
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)