aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2018-07-08 18:53:20 +0900
committerMichael Paquier <michael@paquier.xyz>2018-07-08 18:53:20 +0900
commit677da8c15d19c11465d78f18bfd5ceb5d6fc3af1 (patch)
tree5922d5e71afbebaa190370541bdf02c45fec1345
parent0903bbdad24a8f51b18a6a54a41bbb36ad2ceee4 (diff)
downloadpostgresql-677da8c15d19c11465d78f18bfd5ceb5d6fc3af1.tar.gz
postgresql-677da8c15d19c11465d78f18bfd5ceb5d6fc3af1.zip
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
-rw-r--r--src/backend/catalog/catalog.c15
1 files changed, 4 insertions, 11 deletions
diff --git a/src/backend/catalog/catalog.c b/src/backend/catalog/catalog.c
index 2292deb703a..a42155eeea8 100644
--- a/src/backend/catalog/catalog.c
+++ b/src/backend/catalog/catalog.c
@@ -397,7 +397,6 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
{
RelFileNodeBackend rnode;
char *rpath;
- int fd;
bool collides;
BackendId backend;
@@ -445,12 +444,10 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
/* Check for existing file of same name */
rpath = relpath(rnode, MAIN_FORKNUM);
- fd = BasicOpenFile(rpath, O_RDONLY | PG_BINARY);
- if (fd >= 0)
+ if (access(rpath, F_OK) == 0)
{
/* definite collision */
- close(fd);
collides = true;
}
else
@@ -458,13 +455,9 @@ GetNewRelFileNode(Oid reltablespace, Relation pg_class, char relpersistence)
/*
* Here we have a little bit of a dilemma: if errno is something
* other than ENOENT, should we declare a collision and loop? In
- * particular one might think this advisable for, say, EPERM.
- * However there really shouldn't be any unreadable files in a
- * tablespace directory, and if the EPERM is actually complaining
- * that we can't read the directory itself, we'd be in an infinite
- * loop. In practice it seems best to go ahead regardless of the
- * errno. If there is a colliding file we will get an smgr
- * failure when we attempt to create the new relation file.
+ * practice it seems best to go ahead regardless of the errno. If
+ * there is a colliding file we will get an smgr failure when we
+ * attempt to create the new relation file.
*/
collides = false;
}