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 1jIbW2-0006rU-6K for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Mar 2020 17:14:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jIbVz-0001m4-KO for pgsql-hackers@arkaria.postgresql.org; Sun, 29 Mar 2020 17:14:27 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jIbVz-0001fM-25 for pgsql-hackers@lists.postgresql.org; Sun, 29 Mar 2020 17:14:27 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jIbVs-0004EX-0X for pgsql-hackers@postgresql.org; Sun, 29 Mar 2020 17:14:25 +0000 Received: by mail-qt1-x841.google.com with SMTP id t17so13108621qtn.12 for ; Sun, 29 Mar 2020 10:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=qqgpAFMRImspLDbSm/MiW5IidHmw1vGX8SrPmCUP9Hg=; b=d4U3G0g7yWIyf0R8FXnjJ7SmcwIuJPb/TZ3bgtCucv3678vTpkeayzydNKvXRu5f4w lcs7ypoB2B5UhSUBqmzDlcWhZSnslUGtqiAcdqgDsTuFC2p8dXe/jJHFhHOpwH9iks2O 16LktenjS57zcKglsrRuEQth6Nixdt216mz5gb5XIAN4iIdVBSCgPnbx7le1MlO1+9yE Q7zekLj1gWduBgNmirup/ScmeaWQniD19qEIUrbcUiop9C1Mz0+ucRs7m4Cfa7abL5qI 9EMuxd+kzR2TcbJQyTqrodQLT3ekk3xz6ezR2Btj7BD+aCbuHI8IjZWp4RoiDzW2pAiO BHlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=qqgpAFMRImspLDbSm/MiW5IidHmw1vGX8SrPmCUP9Hg=; b=N5cNMwWgrqTDuEVXI2tHJW0F9YOx9sjULrmnnCTOvxQ9RJqMVa8rXY5zco85PQqh5c rm0oJzB/HyS+OkME8lppIPETzjSI8sjsY5nTbnBsR5di1eCQoDh0hIYM9HVlUrWBBrR1 pjAeoESUy3mUoHeOJ8PpHLgEyTHMuxBEmsbVbMCwgsrP7BhhM+T/90E4b4tTa+n6wSTB s25LBRaQrIfXBzD0r0H8wfx46G2IFkq4Nl4W2/GpiIxvp9Vspl3zm8/FlgewD1Bj5zoM QETLUGy9IheHI8wQoCkoKW/t721fEqREPG467i8wX08fhCpHZVc+nnDkdQgpFllPu+F9 Akiw== X-Gm-Message-State: ANhLgQ3A6GJ7/DXkwJPYjhfZJCIv/NjYoNVzLxlmcQUxshbSbSK4VrGe xHbUJwR+eEridgCaXAfd5ObxGw== X-Google-Smtp-Source: ADFU+vutcUUCmvq9eViVZ8tFi4ZDaBnh9xlK25CR6Ch6hjNVDK2mfmIkE0tsFuk4OuzCbH3l0NJOHg== X-Received: by 2002:ac8:2aef:: with SMTP id c44mr1499017qta.116.1585502058712; Sun, 29 Mar 2020 10:14:18 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id j50sm9335886qta.42.2020.03.29.10.14.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Mar 2020 10:14:17 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id C97328011F5; Sun, 29 Mar 2020 12:14:15 -0500 (CDT) Date: Sun, 29 Mar 2020 12:14:15 -0500 From: Justin Pryzby To: Tom Lane Cc: pgsql-hackers@postgresql.org, Fabien COELHO , Alvaro Herrera , David Steele , "Bossart, Nathan" , Thomas Munro Subject: Re: pg11+: pg_ls_*dir LIMIT 1: temporary files .. not closed at end-of-transaction Message-ID: <20200329171415.GL20103@telsasoft.com> References: <20200311111921.GQ29065@telsasoft.com> <21724.1583955158@sss.pgh.pa.us> <20200312121156.GB29065@telsasoft.com> <20200316155306.GM26184@telsasoft.com> <3061.1584409130@sss.pgh.pa.us> <20200317020017.GT26184@telsasoft.com> <24244.1585415634@sss.pgh.pa.us> <20200328183904.GI20103@telsasoft.com> <28906.1585422475@sss.pgh.pa.us> <27064.1585499825@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <27064.1585499825@sss.pgh.pa.us> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sun, Mar 29, 2020 at 12:37:05PM -0400, Tom Lane wrote: > I wrote: > > Justin Pryzby writes: > >> Maybe we should lstat() the file to determine if it's a dangling link; if > >> lstat() fails, then skip it. Currently, we use stat(), which shows metdata of > >> a link's *target*. Maybe we'd change that. > > > Hm, good point that ENOENT could refer to a symlink's target. Still, > > I'm not sure it's worth going out of our way to disambiguate that, > > given that these directories aren't really supposed to contain symlinks. > > (And on the third hand, if they aren't supposed to, then maybe these > > functions needn't look through any symlinks? In which case just > > substituting lstat for stat would resolve the ambiguity.) > > After looking at the callers of pg_ls_dir_files, and noticing that > it's already defined to ignore anything that's not a regular file, > I think switching to lstat makes sense. Yea, only pg_ls_dir() shows special file types (and currently the others even hide dirs). The essence of your patch is to ignore ENOENT, but you also changed to use lstat(), which seems unrelated. That means we'll now hide (non-broken) symlinks. Is that intentional/needed ? I guess maybe you're trying to fix the bug (?) that symlinks aren't skipped? If so, I guess it should be a separate commit, or the commit message should say so. I think the doc update is already handled by: 8b6d94cf6c8319bfd6bebf8b863a5db586c19c3b (we didn't used to say we skipped specials, and now we say we do, and we'll to follow through RSN and actually do it, too). > diff --git a/src/backend/utils/adt/genfile.c b/src/backend/utils/adt/genfile.c > index 01185f2..8429a12 100644 > --- a/src/backend/utils/adt/genfile.c > +++ b/src/backend/utils/adt/genfile.c > @@ -596,10 +596,15 @@ pg_ls_dir_files(FunctionCallInfo fcinfo, const char *dir, bool missing_ok) > > /* Get the file info */ > snprintf(path, sizeof(path), "%s/%s", dir, de->d_name); > - if (stat(path, &attrib) < 0) > + if (lstat(path, &attrib) < 0) > + { > + /* Ignore concurrently-deleted files, else complain */ > + if (errno == ENOENT) > + continue; > ereport(ERROR, > (errcode_for_file_access(), > errmsg("could not stat file \"%s\": %m", path))); > + } > > /* Ignore anything but regular files */ > if (!S_ISREG(attrib.st_mode))