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 45659864cd1cf642c3ed407ee90ab07707029411..023b46dda7d885b7956c737ec2fb815b9e489abb 100644 (file)
@@ -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 14f42daa7a710d283ca9ec57d95516d82b7b68ad..292a6d103b5a16f5cd8c7396f3f8046afc0f3356 100644 (file)
@@ -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))