From patchwork Wed Oct 26 13:34:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 79422 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp67311qge; Wed, 26 Oct 2016 06:35:00 -0700 (PDT) X-Received: by 10.98.148.18 with SMTP id m18mr4308417pfe.162.1477488900461; Wed, 26 Oct 2016 06:35:00 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id g17si2686019pgn.304.2016.10.26.06.35.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Oct 2016 06:35:00 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-439597-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-439597-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-439597-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; q=dns; s=default; b=AdNxwXaorGWOYMNTik7PTgoLdbJ7oJ H9EPjlZ6/a/Daf/SKQ31tBbqc3IoY+dzLRlPmH824eCu3jY8k9HcPsVUgGqzrYJ9 KevbMMLN0PhEH8sMZx7DkrK/ou6NFbPSqfKBU/V3cWgW39YErJw6wLExlfQNwbz7 Hi84y5KT7hSWY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; s=default; bh=P3kscapw9Z/GeN1QYs9EB+5EX4U=; b=Gh1r rncAV4XTXELBRXWaqtsaCSyRkI3ind/aRl57NRVciE4QlYh7sF+Sd5BEVZuGkLhm vdshHrmch4HhVbe2Z9c54/TtgzLV/nyo5C5xNc16ov8FhD7M4vyILhYTe6hzgSaf XbiWh9OAKUOkOwBuY77hgfEcsrXFQoupQIPMy3s= Received: (qmail 5190 invoked by alias); 26 Oct 2016 13:34:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 3274 invoked by uid 89); 26 Oct 2016 13:34:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:2511, Five, dir.cc, dircc X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 26 Oct 2016 13:34:32 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2236E66CB0; Wed, 26 Oct 2016 13:34:31 +0000 (UTC) Received: from localhost (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9QDYUur025050; Wed, 26 Oct 2016 09:34:30 -0400 Date: Wed, 26 Oct 2016 14:34:29 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: Re: [PATCH] Five patches for std::experimental::filesystem Message-ID: <20161026133429.GV2922@redhat.com> References: <20161024165010.GL2922@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161024165010.GL2922@redhat.com> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) On 24/10/16 17:50 +0100, Jonathan Wakely wrote: > Make directory iterators become end iterator on error > * src/filesystem/dir.cc (open_dir): Return same value for errors > whether ignored or not. > (_Dir::advance(error_code*, directory_options)): Return false on > error. > (directory_iterator(const path&, directory_options, error_code*)): > Create end iterator on error (LWG 2723). > (recursive_directory_iterator(const path&, directory_options, > error_code*)): Likewise. > * testsuite/experimental/filesystem/iterators/directory_iterator.cc: > Update expected behaviour on error. > * testsuite/experimental/filesystem/iterators/ > recursive_directory_iterator.cc: Likewise. I missed the case where recursing into a sub-directory fails, and that happened to be the one bit of the test where I didn't add a new check. Tested x86_64-linux, committed to trunk. commit a38bbf551b4f49e47fe1da03b779edba66240d5f Author: Jonathan Wakely Date: Wed Oct 26 13:34:15 2016 +0100 Fix error handling in recursive_directory_iterator::increment * src/filesystem/dir.cc (recursive_directory_iterator::increment): Reset state on error. * testsuite/experimental/filesystem/iterators/ recursive_directory_iterator.cc: Check state after increment error. diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc index 4640d75..bcd7dd0 100644 --- a/libstdc++-v3/src/filesystem/dir.cc +++ b/libstdc++-v3/src/filesystem/dir.cc @@ -343,7 +343,10 @@ fs::recursive_directory_iterator::increment(error_code& ec) noexcept { _Dir dir = open_dir(top.entry.path(), _M_options, &ec); if (ec) - return *this; + { + _M_dirs.reset(); + return *this; + } if (dir.dirp) _M_dirs->push(std::move(dir)); } diff --git a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc index b41c394..79aa178 100644 --- a/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc +++ b/libstdc++-v3/testsuite/experimental/filesystem/iterators/recursive_directory_iterator.cc @@ -81,6 +81,7 @@ test01() VERIFY( iter->path() == p/"d1/d2" ); iter.increment(ec); // should fail to recurse into p/d1/d2 VERIFY( ec ); + VERIFY( iter == fs::recursive_directory_iterator() ); // Test inaccessible sub-directory, skipping permission denied. iter = fs::recursive_directory_iterator(p, opts, ec);