summaryrefslogtreecommitdiff
path: root/src/backend/commands/tablespace.c
diff options
context:
space:
mode:
authorTom Lane2005-06-19 21:34:03 +0000
committerTom Lane2005-06-19 21:34:03 +0000
commit3f749924f82efd5b2f4b424f6c69a89a2959e4b3 (patch)
tree3bd4c6588dc45f0b88f394e0dee85f201f54d4d0 /src/backend/commands/tablespace.c
parente26b0abda3919448d5ccbcaac0415010022864b7 (diff)
Simplify uses of readdir() by creating a function ReadDir() that
includes error checking and an appropriate ereport(ERROR) message. This gets rid of rather tedious and error-prone manipulation of errno, as well as a Windows-specific bug workaround, at more than a dozen call sites. After an idea in a recent patch by Heikki Linnakangas.
Diffstat (limited to 'src/backend/commands/tablespace.c')
-rw-r--r--src/backend/commands/tablespace.c51
1 files changed, 4 insertions, 47 deletions
diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index fac20708c0d..a469a8fa349 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.21 2005/06/06 20:22:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/tablespace.c,v 1.22 2005/06/19 21:34:01 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -519,23 +519,16 @@ remove_tablespace_directories(Oid tablespaceoid, bool redo)
pfree(location);
return true;
}
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not open directory \"%s\": %m",
- location)));
+ /* else let ReadDir report the error */
}
- errno = 0;
- while ((de = readdir(dirdesc)) != NULL)
+ while ((de = ReadDir(dirdesc, location)) != NULL)
{
/* Note we ignore PG_VERSION for the nonce */
if (strcmp(de->d_name, ".") == 0 ||
strcmp(de->d_name, "..") == 0 ||
strcmp(de->d_name, "PG_VERSION") == 0)
- {
- errno = 0;
continue;
- }
subfile = palloc(strlen(location) + 1 + strlen(de->d_name) + 1);
sprintf(subfile, "%s/%s", location, de->d_name);
@@ -555,22 +548,8 @@ remove_tablespace_directories(Oid tablespaceoid, bool redo)
subfile)));
pfree(subfile);
- errno = 0;
}
-#ifdef WIN32
- /*
- * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
- * not in released version
- */
- if (GetLastError() == ERROR_NO_MORE_FILES)
- errno = 0;
-#endif
- if (errno)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not read directory \"%s\": %m",
- location)));
FreeDir(dirdesc);
/*
@@ -685,38 +664,16 @@ directory_is_empty(const char *path)
struct dirent *de;
dirdesc = AllocateDir(path);
- if (dirdesc == NULL)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not open directory \"%s\": %m",
- path)));
- errno = 0;
- while ((de = readdir(dirdesc)) != NULL)
+ while ((de = ReadDir(dirdesc, path)) != NULL)
{
if (strcmp(de->d_name, ".") == 0 ||
strcmp(de->d_name, "..") == 0)
- {
- errno = 0;
continue;
- }
FreeDir(dirdesc);
return false;
}
-#ifdef WIN32
- /*
- * This fix is in mingw cvs (runtime/mingwex/dirent.c rev 1.4), but
- * not in released version
- */
- if (GetLastError() == ERROR_NO_MORE_FILES)
- errno = 0;
-#endif
- if (errno)
- ereport(ERROR,
- (errcode_for_file_access(),
- errmsg("could not read directory \"%s\": %m",
- path)));
FreeDir(dirdesc);
return true;
}