Re: Remove sort files

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Remove sort files
Date: 2001-05-24 14:26:50
Message-ID: 200105241426.f4OEQpH08008@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

> Bruce Momjian writes:
>
> > OK, I did the readdir() thing. I hope it is safe to unlink a file while
> > in a readdir() loop.
>
> The only portable member of struct dirent is d_name. (Do you really
> expect non-regular files in the sort directory?) Also, lots of error
> checks (after opendir, readdir, mkdir, unlink) are missing.

Error checks missing in my code or elsewhere? Also, what should I do on
an unlink failure? I thought of printing a message but wasn't sure:

if ((db_dir = opendir(db_path)) != NULL)
while ((db_de = readdir(db_dir)) != NULL)
{
snprintf(temp_path, sizeof(temp_path),
"%s/%s/%s/", db_path, db_de->d_name, SORT_TEMP_DIR);
if ((temp_dir = opendir(temp_path)) != NULL)
while ((temp_de = readdir(temp_dir)) != NULL)
{
if (strspn(temp_de->d_name, "0123456789.") ==
strlen(temp_de->d_name))
{
snprintf(rm_path, sizeof(temp_path),
"%s/%s/%s/%s",
db_path, db_de->d_name,
SORT_TEMP_DIR, temp_de->d_name);
unlink(rm_path);
}
}
}

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Jason Tishler 2001-05-24 15:28:59 Cygwin Java (make install) Patch
Previous Message Peter Eisentraut 2001-05-24 08:35:12 Re: Remove sort files