summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/adt/dbsize.c5
-rw-r--r--src/backend/utils/adt/genfile.c2
-rw-r--r--src/backend/utils/adt/misc.c15
-rw-r--r--src/backend/utils/cache/relcache.c16
-rw-r--r--src/backend/utils/time/snapmgr.c26
5 files changed, 20 insertions, 44 deletions
diff --git a/src/backend/utils/adt/dbsize.c b/src/backend/utils/adt/dbsize.c
index 515e30d177..58c0b01bdc 100644
--- a/src/backend/utils/adt/dbsize.c
+++ b/src/backend/utils/adt/dbsize.c
@@ -110,11 +110,6 @@ calculate_database_size(Oid dbOid)
/* Scan the non-default tablespaces */
snprintf(dirpath, MAXPGPATH, "pg_tblspc");
dirdesc = AllocateDir(dirpath);
- if (!dirdesc)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not open tablespace directory \"%s\": %m",
- dirpath)));
while ((direntry = ReadDir(dirdesc, dirpath)) != NULL)
{
diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c
index b3b9fc522d..04f1efbe4b 100644
--- a/src/backend/utils/adt/genfile.c
+++ b/src/backend/utils/adt/genfile.c
@@ -508,7 +508,7 @@ pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir)
if (!fctx->dirdesc)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not read directory \"%s\": %m",
+ errmsg("could not open directory \"%s\": %m",
fctx->location)));
funcctx->user_fctx = fctx;
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c
index 1980ff5ac7..f53d411ad1 100644
--- a/src/backend/utils/adt/misc.c
+++ b/src/backend/utils/adt/misc.c
@@ -26,6 +26,7 @@
#include "catalog/pg_tablespace.h"
#include "catalog/pg_type.h"
#include "commands/dbcommands.h"
+#include "commands/tablespace.h"
#include "common/keywords.h"
#include "funcapi.h"
#include "miscadmin.h"
@@ -425,9 +426,9 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
while ((de = ReadDir(fctx->dirdesc, fctx->location)) != NULL)
{
- char *subdir;
- DIR *dirdesc;
Oid datOid = atooid(de->d_name);
+ char *subdir;
+ bool isempty;
/* this test skips . and .., but is awfully weak */
if (!datOid)
@@ -436,16 +437,10 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
/* if database subdir is empty, don't report tablespace as used */
subdir = psprintf("%s/%s", fctx->location, de->d_name);
- dirdesc = AllocateDir(subdir);
- while ((de = ReadDir(dirdesc, subdir)) != NULL)
- {
- if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0)
- break;
- }
- FreeDir(dirdesc);
+ isempty = directory_is_empty(subdir);
pfree(subdir);
- if (!de)
+ if (isempty)
continue; /* indeed, nothing in it */
SRF_RETURN_NEXT(funcctx, ObjectIdGetDatum(datOid));
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 1908420d82..12a5f157c0 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -6119,14 +6119,8 @@ RelationCacheInitFileRemove(void)
/* Scan the tablespace link directory to find non-default tablespaces */
dir = AllocateDir(tblspcdir);
- if (dir == NULL)
- {
- elog(LOG, "could not open tablespace link directory \"%s\": %m",
- tblspcdir);
- return;
- }
- while ((de = ReadDir(dir, tblspcdir)) != NULL)
+ while ((de = ReadDirExtended(dir, tblspcdir, LOG)) != NULL)
{
if (strspn(de->d_name, "0123456789") == strlen(de->d_name))
{
@@ -6150,14 +6144,8 @@ RelationCacheInitFileRemoveInDir(const char *tblspcpath)
/* Scan the tablespace directory to find per-database directories */
dir = AllocateDir(tblspcpath);
- if (dir == NULL)
- {
- elog(LOG, "could not open tablespace directory \"%s\": %m",
- tblspcpath);
- return;
- }
- while ((de = ReadDir(dir, tblspcpath)) != NULL)
+ while ((de = ReadDirExtended(dir, tblspcpath, LOG)) != NULL)
{
if (strspn(de->d_name, "0123456789") == strlen(de->d_name))
{
diff --git a/src/backend/utils/time/snapmgr.c b/src/backend/utils/time/snapmgr.c
index addf87dc3b..0b032905a5 100644
--- a/src/backend/utils/time/snapmgr.c
+++ b/src/backend/utils/time/snapmgr.c
@@ -1619,27 +1619,25 @@ DeleteAllExportedSnapshotFiles(void)
DIR *s_dir;
struct dirent *s_de;
- if (!(s_dir = AllocateDir(SNAPSHOT_EXPORT_DIR)))
- {
- /*
- * We really should have that directory in a sane cluster setup. But
- * then again if we don't, it's not fatal enough to make it FATAL.
- * Since we're running in the postmaster, LOG is our best bet.
- */
- elog(LOG, "could not open directory \"%s\": %m", SNAPSHOT_EXPORT_DIR);
- return;
- }
+ /*
+ * Problems in reading the directory, or unlinking files, are reported at
+ * LOG level. Since we're running in the startup process, ERROR level
+ * would prevent database start, and it's not important enough for that.
+ */
+ s_dir = AllocateDir(SNAPSHOT_EXPORT_DIR);
- while ((s_de = ReadDir(s_dir, SNAPSHOT_EXPORT_DIR)) != NULL)
+ while ((s_de = ReadDirExtended(s_dir, SNAPSHOT_EXPORT_DIR, LOG)) != NULL)
{
if (strcmp(s_de->d_name, ".") == 0 ||
strcmp(s_de->d_name, "..") == 0)
continue;
snprintf(buf, sizeof(buf), SNAPSHOT_EXPORT_DIR "/%s", s_de->d_name);
- /* Again, unlink failure is not worthy of FATAL */
- if (unlink(buf))
- elog(LOG, "could not unlink file \"%s\": %m", buf);
+
+ if (unlink(buf) != 0)
+ ereport(LOG,
+ (errcode_for_file_access(),
+ errmsg("could not remove file \"%s\": %m", buf)));
}
FreeDir(s_dir);