On Mon, Mar 16, 2020 at 04:20:21PM +0100, Fabien COELHO wrote: > > About v11, ISTM that the recursive function should check for symbolic links > and possibly avoid them: > > sh> cd data/base > sh> ln -s .. foo > > psql> SELECT * FROM pg_ls_dir_recurse('.'); > ERROR: could not stat file > "./base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo/base/foo": > Too many levels of symbolic links > CONTEXT: SQL function "pg_ls_dir_recurse" statement 1 > > This probably means using lstat instead of (in supplement to?) stat, and > probably tell if something is a link, and if so not recurse in them.
Thanks for looking. I think that opens up a can of worms. I don't want to go into the business of re-implementing all of find(1) - I count ~128 flags (most of which take arguments). You're referring to find -L vs find -P, and some people would want one and some would want another. And don't forget about find -H... pg_stat_file doesn't expose the file type (I guess because it's not portable?), and I think it's outside the scope of this patch to change that. Maybe it suggests that the pg_ls_dir_recurse patch should be excluded. ISTM if someone wants to recursively list a directory, they should avoid putting cycles there, or permission errors, or similar. Or they should write their own C extension that borrows from pg_ls_dir_files but handles more arguments. -- Justin