Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oMd2f-0005bw-7R for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Aug 2022 22:22:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oMd2e-0000pA-3g for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Aug 2022 22:22:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oMd2d-0000p1-Qj for pgsql-hackers@lists.postgresql.org; Fri, 12 Aug 2022 22:22:07 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oMd2b-0007jB-BH for pgsql-hackers@postgresql.org; Fri, 12 Aug 2022 22:22:07 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1oMd2X-001Fki-3R; Fri, 12 Aug 2022 18:22:01 -0400 Date: Fri, 12 Aug 2022 18:22:01 -0400 From: Bruce Momjian To: Wei Sun <936739278@qq.com> Cc: pgsql-hackers Subject: Re: Add lasterrno setting for dir_existsfile() Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, Jan 10, 2022 at 12:19:28AM +0800, Wei Sun wrote: > Hi, > > Some time ago,the following patch clean up error handling in pg_basebackup's > walmethods.c. > https://github.com/postgres/postgres/commit/248c3a9 > > This patch keep the error state in the DirectoryMethodData struct, > in most functions, the lasterrno is set correctly, but in function > dir_existsfile(), > the lasterrno is not set when the file fails to open. > > If this is a correction omission, I think this patch can fix this. > > Cheers > diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c > index f74bd13..35cf5a8 100644 > --- a/src/bin/pg_basebackup/walmethods.c > +++ b/src/bin/pg_basebackup/walmethods.c > @@ -580,7 +580,10 @@ dir_existsfile(const char *pathname) > > fd = open(tmppath, O_RDONLY | PG_BINARY, 0); > if (fd < 0) > + { > + dir_data->lasterrno = errno; > return false; > + } > close(fd); > return true; > } Looking at this, the function is used to check if something exists, and return a boolean. I am not sure it is helpful to also return a ENOENT in the lasterrno status field. It might be useful to set lasterrno if the open fails and it is _not_ ENOENT. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Indecision is a decision. Inaction is an action. Mark Batterson