1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

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.
This commit is contained in:
Tom Lane
2005-06-19 21:34:03 +00:00
parent e26b0abda3
commit 3f749924f8
10 changed files with 88 additions and 223 deletions

View File

@ -5,7 +5,7 @@
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
*
* IDENTIFICATION
* $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.17 2005/05/27 00:57:48 neilc Exp $
* $PostgreSQL: pgsql/contrib/dbsize/dbsize.c,v 1.18 2005/06/19 21:34:00 tgl Exp $
*
*/
@ -58,7 +58,7 @@ db_dir_size(const char *path)
if (!dirdesc)
return 0;
while ((direntry = readdir(dirdesc)) != NULL)
while ((direntry = ReadDir(dirdesc, path)) != NULL)
{
struct stat fst;
@ -97,13 +97,8 @@ calculate_database_size(Oid dbOid)
/* Scan the non-default tablespaces */
snprintf(pathname, MAXPGPATH, "%s/pg_tblspc", DataDir);
dirdesc = AllocateDir(pathname);
if (!dirdesc)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open tablespace directory \"%s\": %m",
pathname)));
while ((direntry = readdir(dirdesc)) != NULL)
while ((direntry = ReadDir(dirdesc, pathname)) != NULL)
{
if (strcmp(direntry->d_name, ".") == 0 ||
strcmp(direntry->d_name, "..") == 0)
@ -147,13 +142,7 @@ pg_tablespace_size(PG_FUNCTION_ARGS)
dirdesc = AllocateDir(tblspcPath);
if (!dirdesc)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open tablespace directory \"%s\": %m",
tblspcPath)));
while ((direntry = readdir(dirdesc)) != NULL)
while ((direntry = ReadDir(dirdesc, tblspcPath)) != NULL)
{
struct stat fst;