Re: Errno checks for rmtree() - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Errno checks for rmtree()
Date
Msg-id 200502130229.j1D2T3W11362@candle.pha.pa.us
Whole thread Raw
In response to Re: Errno checks for rmtree()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
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;
  }

pgsql-patches by date:

Previous
From: Tom Lane
Date:
Subject: Re: Errno checks for rmtree()
Next
From: "Magnus Hagander"
Date:
Subject: Re: [BUGS] BUG #1466: #maintenace_work_mem = 16384