Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jDuRP-0000Lx-H9 for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2020 18:26:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jDuRM-0000bE-Nb for pgsql-hackers@arkaria.postgresql.org; Mon, 16 Mar 2020 18:26:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jDuRM-0000b7-Ej for pgsql-hackers@lists.postgresql.org; Mon, 16 Mar 2020 18:26:16 +0000 Received: from courriel.mines-paristech.fr ([77.158.173.149] helo=antispam-1.ensmp.fr) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jDuRI-0005z8-Oa for pgsql-hackers@postgresql.org; Mon, 16 Mar 2020 18:26:15 +0000 Received: from smtp-5.mines-paristech.fr (smtp.mines-paristech.fr [77.158.173.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by antispam-1.ensmp.fr (antispam.mines-paristech.fr) with ESMTPS id 2196156947; Mon, 16 Mar 2020 19:21:08 +0100 (CET) Received: from pseudo (126.237.219.88.rev.sfr.net [88.219.237.126]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp-5.mines-paristech.fr (Postfix) with ESMTPSA id 9908D20057; Mon, 16 Mar 2020 19:21:07 +0100 (CET) Date: Mon, 16 Mar 2020 19:21:06 +0100 (CET) From: Fabien COELHO X-X-Sender: fabien@pseudo To: Justin Pryzby cc: Alvaro Herrera , David Steele , pgsql-hackers@postgresql.org, "Bossart, Nathan" , Thomas Munro , Tom Lane Subject: Re: pg_ls_tmpdir to show directories and shared filesets (and pg_ls_*) In-Reply-To: <20200316154136.GK26184@telsasoft.com> Message-ID: References: <20200303202313.GA28076@alvherre.pgsql> <20200305161838.GJ684@telsasoft.com> <20200306233507.GN684@telsasoft.com> <20200307214010.GB1357@telsasoft.com> <20200310183037.GA29065@telsasoft.com> <20200313131232.GO29065@telsasoft.com> <20200315212729.GC26184@telsasoft.com> <20200316154136.GK26184@telsasoft.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-CLAMAV-SCAN: ok X-VRSPAM-SCORE: -100 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrgedugedrudeffedguddutdcutefuodetggdotefrucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepfffhvffujgfkfhgfgggtsehttdertddtredvnecuhfhrohhmpefhrggsihgvnhcuvefqgffnjffquceotghovghlhhhosegtrhhirdgvnhhsmhhprdhfrheqnecukfhppeekkedrvdduledrvdefjedruddvieenucfrrghrrghmpehmohguvgepshhmthhpohhuth X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello Justin, >> 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... This is not the point. The point is that a link can change a finite tree into cyclic graph, and you do not want to delve into that, ever. The "find" command, by default, does not recurse into a link because of said problem, and the user *must* ask for it and assume the infinite loop if any. So if you implement one behavior, it should be not recursing into links. Franckly, I would not provide the recurse into link alternative, but it could be implemented if someone wants it, and the problem that come with it. > pg_stat_file doesn't expose the file type (I guess because it's not portable?), You are right that Un*x and Windows are not the same wrt link. It seems that there is already something about that in port: "./src/port/dirmod.c:pgwin32_is_junction(const char *path)" So most of the details are already hidden. > 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. IMHO, I really think that it should be included. Dealing with links is no big deal, but you need an additional column in _metadata to tell it is a link, and there is a ifdef because testing is a little different between unix and windows. I'd guess around 10-20 lines of code added. > ISTM if someone wants to recursively list a directory, they should avoid > putting cycles there, or permission errors, or similar. Hmmm. I'd say the user should like to be able to call the function and never have a bad experience with it such as a failure on an infinite loop. > Or they should write their own C extension that borrows from > pg_ls_dir_files but handles more arguments. ISTM that the point of your patch is to provide the basic tool needed to list directories contents, and handling links somehow is a necessary part of that. -- Fabien.