Unix Technical Forum

Re: Errno checks for rmtree()

This is a discussion on Re: Errno checks for rmtree() within the Pgsql Patches forums, part of the PostgreSQL category; --> Bruce Momjian <pgman@candle.pha.pa.us> writes: > + elog(WARNING, "can not remove \"%s\": %s", filepath, strerror(errno)); "could not remove", please; read ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 12:03 AM
Tom Lane
 
Posts: n/a
Default Re: Errno checks for rmtree()

Bruce Momjian <pgman@candle.pha.pa.us> writes:
> + elog(WARNING, "can not remove \"%s\": %s", filepath, strerror(errno));


"could not remove", please; read the message style guidelines.
Also, what's wrong with using %m here?

Otherwise it looks good.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-18-2008, 12:03 AM
Bruce Momjian
 
Posts: n/a
Default Re: Errno checks for rmtree()

Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > + elog(WARNING, "can not remove \"%s\": %s", filepath, strerror(errno));

>
> "could not remove", please; read the message style guidelines.
> Also, what's wrong with using %m here?
>
> Otherwise it looks good.


OK, new version attached.

--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

Index: src/port/dirmod.c
================================================== =================
RCS file: /cvsroot/pgsql/src/port/dirmod.c,v
retrieving revision 1.34
diff -c -c -r1.34 dirmod.c
*** src/port/dirmod.c 31 Dec 2004 22:03:53 -0000 1.34
--- src/port/dirmod.c 13 Feb 2005 02:23:22 -0000
***************
*** 350,355 ****
--- 350,356 ----
return filenames;
}

+
/*
* fnames_cleanup
*
***************
*** 366,371 ****
--- 367,373 ----
pfree(filenames);
}

+
/*
* rmtree
*
***************
*** 398,413 ****
snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);

if (stat(filepath, &statbuf) != 0)
! {
! fnames_cleanup(filenames);
! return false;
! }

if (S_ISDIR(statbuf.st_mode))
{
/* call ourselves recursively for a directory */
if (!rmtree(filepath, true))
{
fnames_cleanup(filenames);
return false;
}
--- 400,413 ----
snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);

if (stat(filepath, &statbuf) != 0)
! goto report_and_fail;

if (S_ISDIR(statbuf.st_mode))
{
/* call ourselves recursively for a directory */
if (!rmtree(filepath, true))
{
+ /* we already reported the error */
fnames_cleanup(filenames);
return false;
}
***************
*** 415,436 ****
else
{
if (unlink(filepath) != 0)
! {
! fnames_cleanup(filenames);
! return false;
! }
}
}

if (rmtopdir)
{
if (rmdir(path) != 0)
! {
! fnames_cleanup(filenames);
! return false;
! }
}

fnames_cleanup(filenames);
return true;
}
--- 415,440 ----
else
{
if (unlink(filepath) != 0)
! goto report_and_fail;
}
}

if (rmtopdir)
{
if (rmdir(path) != 0)
! goto report_and_fail;
}

fnames_cleanup(filenames);
return true;
+
+ report_and_fail:
+
+ #ifndef FRONTEND
+ elog(WARNING, "could not remove file or directory \"%s\": %m", filepath);
+ #else
+ fprintf(stderr, "could not remove file or directory \"%s\": %s\n", filepath, strerror(errno));
+ #endif
+ fnames_cleanup(filenames);
+ return false;
}


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:20 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com