copydir() and rmtree() need to use lstat, not stat, to behave as expected
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Jul 2006 22:36:46 +0000 (22:36 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 18 Jul 2006 22:36:46 +0000 (22:36 +0000)
with symlinks.  Noted while trying to use rmtree in new C-code pg_regress.

src/port/copydir.c
src/port/dirmod.c

index 718d99251b781aae573c4ea418b3b18d04c9515b..ef441e5ad3ff1fc1d4fe617df8fea89b3fcd0e04 100644 (file)
@@ -11,7 +11,7 @@
  * as a service.
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/port/copydir.c,v 1.17 2006/03/05 15:59:10 momjian Exp $
+ *   $PostgreSQL: pgsql/src/port/copydir.c,v 1.18 2006/07/18 22:36:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -75,7 +75,7 @@ copydir(char *fromdir, char *todir, bool recurse)
        snprintf(fromfile, MAXPGPATH, "%s/%s", fromdir, xlde->d_name);
        snprintf(tofile, MAXPGPATH, "%s/%s", todir, xlde->d_name);
 
-       if (stat(fromfile, &fst) < 0)
+       if (lstat(fromfile, &fst) < 0)
            ereport(ERROR,
                    (errcode_for_file_access(),
                     errmsg("could not stat file \"%s\": %m", fromfile)));
index d806a9ba8d701a4adb8c0a5488228b8e79eb5a37..e58384a749cbc59b8afaf0fbedca7a8cdab15277 100644 (file)
@@ -10,7 +10,7 @@
  * Win32 (NT, Win2k, XP).  replace() doesn't work on Win95/98/Me.
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/port/dirmod.c,v 1.42 2006/03/05 15:59:10 momjian Exp $
+ *   $PostgreSQL: pgsql/src/port/dirmod.c,v 1.43 2006/07/18 22:36:46 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -434,7 +434,7 @@ rmtree(char *path, bool rmtopdir)
    {
        snprintf(filepath, MAXPGPATH, "%s/%s", path, *filename);
 
-       if (stat(filepath, &statbuf) != 0)
+       if (lstat(filepath, &statbuf) != 0)
            goto report_and_fail;
 
        if (S_ISDIR(statbuf.st_mode))