Hello
We have some functions for directory listing, e.g. pg_ls_dir, pg_ls_logdir, 
pg_ls_waldir. All of them call pg_ls_dir_files function 
(src/backend/utils/adt/genfile.c) and i have question about per file error in 
this function.

>               /* Get the file info */
>               snprintf(path, sizeof(path), "%s/%s", fctx->location, 
> de->d_name);
>               if (stat(path, &attrib) < 0)
>                       ereport(ERROR,
>                                       (errcode_for_file_access(),
>                                        errmsg("could not stat directory 
> \"%s\": %m", dir)));

We tried stat file in direectory, but error say only about directory. For 
example it is possible have very unexpected (and fearful) error for pg_ls_dir 
during checkpoint:

> postgres=# SELECT sum(size) AS size_bytes FROM pg_ls_waldir();
> ERROR:  could not stat directory "pg_wal": No such file or directory

It is expected? Maybe it is better skip ENOENT files during directory listing? 
Or change error to "could not stat file in directory \"%s\"" if we do not want 
report filename for some reason. Or report error for file path instead of dir.

regards, Sergei

Reply via email to