mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
Fix a race condition that caused pg_database_size() and pg_tablespace_size()
to fail if an object was removed between calls to ReadDir() and stat(). Per discussion in pgsql-hackers. http://archives.postgresql.org/pgsql-hackers/2007-03/msg00671.php Bug report and patch by Michael Fuhr.
This commit is contained in:
parent
15c31ce09e
commit
3cda014bf4
@ -5,7 +5,7 @@
|
|||||||
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
|
* Copyright (c) 2002-2005, PostgreSQL Global Development Group
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.7 2005/10/29 00:31:51 petere Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/dbsize.c,v 1.7.2.1 2007/03/11 06:43:23 alvherre Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -51,10 +51,14 @@ db_dir_size(const char *path)
|
|||||||
snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name);
|
snprintf(filename, MAXPGPATH, "%s/%s", path, direntry->d_name);
|
||||||
|
|
||||||
if (stat(filename, &fst) < 0)
|
if (stat(filename, &fst) < 0)
|
||||||
ereport(ERROR,
|
{
|
||||||
(errcode_for_file_access(),
|
if (errno == ENOENT)
|
||||||
errmsg("could not stat file \"%s\": %m", filename)));
|
continue;
|
||||||
|
else
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode_for_file_access(),
|
||||||
|
errmsg("could not stat file \"%s\": %m", filename)));
|
||||||
|
}
|
||||||
dirsize += fst.st_size;
|
dirsize += fst.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,9 +177,14 @@ calculate_tablespace_size(Oid tblspcOid)
|
|||||||
snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name);
|
snprintf(pathname, MAXPGPATH, "%s/%s", tblspcPath, direntry->d_name);
|
||||||
|
|
||||||
if (stat(pathname, &fst) < 0)
|
if (stat(pathname, &fst) < 0)
|
||||||
ereport(ERROR,
|
{
|
||||||
(errcode_for_file_access(),
|
if (errno == ENOENT)
|
||||||
errmsg("could not stat file \"%s\": %m", pathname)));
|
continue;
|
||||||
|
else
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode_for_file_access(),
|
||||||
|
errmsg("could not stat file \"%s\": %m", pathname)));
|
||||||
|
}
|
||||||
|
|
||||||
if (fst.st_mode & S_IFDIR)
|
if (fst.st_mode & S_IFDIR)
|
||||||
totalsize += db_dir_size(pathname);
|
totalsize += db_dir_size(pathname);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user