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 1pGsZb-0003nA-C8 for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Jan 2023 02:16:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pGsZY-0005yq-I0 for pgsql-hackers@arkaria.postgresql.org; Sun, 15 Jan 2023 02:16:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pGsZY-0005yP-3h for pgsql-hackers@lists.postgresql.org; Sun, 15 Jan 2023 02:16:36 +0000 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pGsZU-0006fq-AI for pgsql-hackers@postgresql.org; Sun, 15 Jan 2023 02:16:34 +0000 Received: by mail-qt1-x831.google.com with SMTP id h21so22065053qta.12 for ; Sat, 14 Jan 2023 18:16:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:from:to:cc:subject:date:message-id:reply-to; bh=Gsp4eEowx7kelJFxdST1MWQPH22s28VfRTOt8l2YW+s=; b=Ny5v+0e+P6oqsh9dZFNbS4qrwTk7//K0EVehAFx70s3Nr4kH5ON0HBNIe502EX/O77 8aiWMbWSTIwQLuza8I0yUYXObolMNwhBVdAvZ4M2mBDQbYGfE1euXZkFC0oKPPuzlwW/ 5O4YSkzF7UHYa9etqOeczGLDqVdI53NAyQ+iikQ55DxwxyuNulfxr5TuuYhfejNW+Gpt HmBoxa+wVqfd+NTIuIOr/0NcNHtEMfY0fqX08to9gzaa4Y+oBTYkwAiLRtO5twFsi7BO rlmVJxqY73UU2JCJVmv2r6+4056fDJHwSQB+3xyaJNOMUnjH3qxLyGQcYlPRiB7PuH48 /akw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:content-disposition:mime-version:message-id:subject:to :from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Gsp4eEowx7kelJFxdST1MWQPH22s28VfRTOt8l2YW+s=; b=7dmr76B6SbD2i+VnQc3HpJ82I3haTRAtnSAsHr3wqSgq+MkDYq3K4hEI5pHp0/QJHW nSSKebnIjTFvV1IBhINsSoCiAQX5yHGx+U6G76LmsXlbcRZbhoUMvgoRXnlKA4Glttjs YLcbwyJ+8iWV1Mn3Y/JE2cXZklqXgC4VixzU05O21a+dnKuXXMbdPymElqJRQH7vq8K5 fi5Lq8pAXxZOxO5ibGwFU+TLd05KTHgkQgbdnitYq1FKoQZ9p1AgAZKb9/oHxdfiXMYe D0HPJAu0oNhGiG4KmsHcBfd06mGdrxF8KhJ9mAMGtnW5lYhQ5KHA+02psq0RCpb7uDsl M0Bw== X-Gm-Message-State: AFqh2kq9hD8arQ9q3TjIYvGKwv4lWcpVGNL2ALIkpfhqcD5ejsn99Zsd vAthuVw9ungFf32IfDULFoVTx6Ordc4FiBUC X-Google-Smtp-Source: AMrXdXu91HFgB+SUQFDl7oE2T0SGq5RialFUhaN3p/9PKvOLdFHxV4v1UmiTYukBqR9UJUzuVbI3Vw== X-Received: by 2002:a05:622a:1e17:b0:3a8:21cb:11d2 with SMTP id br23-20020a05622a1e1700b003a821cb11d2mr117054176qtb.1.1673748990136; Sat, 14 Jan 2023 18:16:30 -0800 (PST) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id g5-20020ac84b65000000b00398ed306034sm12753653qts.81.2023.01.14.18.16.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Jan 2023 18:16:29 -0800 (PST) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 32E58800BF2; Sat, 14 Jan 2023 20:16:28 -0600 (CST) Date: Sat, 14 Jan 2023 20:16:28 -0600 From: Justin Pryzby To: pgsql-hackers@postgresql.org Subject: [PATCH] pg_restore: use strerror for errors other than ENOENT Message-ID: <20230115021627.GD9837@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Without this patch: $ mkdir 000; chmod 000 ./000 $ strace -fe open,stat ./tmp_install/usr/local/pgsql/bin/pg_restore -vvv -l ./000 ... pg_restore: allocating AH for ./000, format 0 pg_restore: attempting to ascertain archive format stat("./000", {st_mode=S_IFDIR|000, st_size=4096, ...}) = 0 stat("./000/toc.dat", 0x7ffc679fb3a0) = -1 EACCES (Permission denied) stat("./000/toc.dat.gz", 0x7ffc679fb3a0) = -1 EACCES (Permission denied) pg_restore: error: directory "./000" does not appear to be a valid archive ("toc.dat" does not exist) +++ exited with 1 +++ With: stat("./000/toc.dat", 0x7ffc29ad0eb0) = -1 EACCES (Permission denied) pg_restore: error: could not open input file "./000": Permission denied I "learned" some time ago to infer what the error message should have said, and finally wrote this so it does what it should. I'd consider this a backpatchable fix to save people the trouble of diagnosing the meaning of the error message. commit 45722852d98b8e9c2702aabe2745d7df200da124 Author: Justin Pryzby Date: Sat Jan 14 19:51:31 2023 -0600 pg_restore: use strerror for errors other than ENOENT diff --git a/src/bin/pg_dump/pg_backup_archiver.c b/src/bin/pg_dump/pg_backup_archiver.c index 7f7a0f1ce7b..e36ee7af157 100644 --- a/src/bin/pg_dump/pg_backup_archiver.c +++ b/src/bin/pg_dump/pg_backup_archiver.c @@ -2107,7 +2107,12 @@ _discoverArchiveFormat(ArchiveHandle *AH) if (snprintf(buf, MAXPGPATH, "%s/toc.dat", AH->fSpec) >= MAXPGPATH) pg_fatal("directory name too long: \"%s\"", AH->fSpec); - if (stat(buf, &st) == 0 && S_ISREG(st.st_mode)) + if (stat(buf, &st) != 0) + { + if (errno != ENOENT) + pg_fatal("could not open input file \"%s\": %m", AH->fSpec); + } + else if (S_ISREG(st.st_mode)) { AH->format = archDirectory; return AH->format; @@ -2117,7 +2122,12 @@ _discoverArchiveFormat(ArchiveHandle *AH) if (snprintf(buf, MAXPGPATH, "%s/toc.dat.gz", AH->fSpec) >= MAXPGPATH) pg_fatal("directory name too long: \"%s\"", AH->fSpec); - if (stat(buf, &st) == 0 && S_ISREG(st.st_mode)) + if (stat(buf, &st) != 0) + { + if (errno != ENOENT) + pg_fatal("could not open input file \"%s\": %m", AH->fSpec); + } + else if (S_ISREG(st.st_mode)) { AH->format = archDirectory; return AH->format;