Hi,
On 2022-08-27 14:06:32 +0530, Bharath Rupireddy wrote:
> @@ -50,7 +51,7 @@ copydir(char *fromdir, char *todir, bool recurse)
>
> while ((xlde = ReadDir(xldir, fromdir)) != NULL)
> {
> - struct stat fst;
> + PGFileType xlde_type;
>
> /* If we got a cancel signal during the copy of the directory, quit */
> CHECK_FOR_INTERRUPTS();
> @@ -62,18 +63,15 @@ copydir(char *fromdir, char *todir, bool recurse)
> snprintf(fromfile, sizeof(fromfile), "%s/%s", fromdir, xlde->d_name);
> snprintf(tofile, sizeof(tofile), "%s/%s", todir, xlde->d_name);
>
> - if (lstat(fromfile, &fst) < 0)
> - ereport(ERROR,
> - (errcode_for_file_access(),
> - errmsg("could not stat file \"%s\": %m", fromfile)));
> + xlde_type = get_dirent_type(fromfile, xlde, false, ERROR);
>
> - if (S_ISDIR(fst.st_mode))
> + if (xlde_type == PGFILETYPE_DIR)
> {
> /* recurse to handle subdirectories */
> if (recurse)
> copydir(fromfile, tofile, true);
> }
> - else if (S_ISREG(fst.st_mode))
> + else if (xlde_type == PGFILETYPE_REG)
> copy_file(fromfile, tofile);
> }
> FreeDir(xldir);
It continues to make no sense to me to add behaviour changes around
error-handling as part of a conversion to get_dirent_type(). I don't at all
understand why e.g. the above change to make copydir() silently skip over
files it can't stat is ok?
Greetings,
Andres Freund