]> gcc.gnu.org Git - gcc.git/commit
libstdc++: Improve directory iterator abstractions for openat
authorJonathan Wakely <jwakely@redhat.com>
Mon, 27 Jun 2022 13:43:54 +0000 (14:43 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 3 Aug 2022 13:38:30 +0000 (14:38 +0100)
commit3df2f035871e913b94a35d4b5c12d37828f313f7
tree17d977d836e31654dffb4fc686b0f337e807b802
parent1a9681e60964c7f7ce0892e14745e6dcf6100157
libstdc++: Improve directory iterator abstractions for openat

Currently the _Dir::open_subdir function decides whether to construct a
_Dir_base with just a pathname, or a file descriptor and pathname. But
that means it is tightly coupled to the implementation of
_Dir_base::openat, which is what actually decides whether to use a file
descriptor or not. If the derived class passes a file descriptor and
filename, but the base class expects a full path and ignores the file
descriptor, then recursive_directory_iterator cannot recurse.

This change introduces a new type that provides the union of all the
information available to the derived class (the full pathname, as well
as a file descriptor for a directory and another pathname relative to
that directory). This allows the derived class to be agnostic to how the
base class will use that information.

libstdc++-v3/ChangeLog:

* src/c++17/fs_dir.cc (_Dir::dir_and_pathname):: Replace with
current() returning _At_path.
(_Dir::_Dir, _Dir::open_subdir, _Dir::do_unlink): Adjust.
* src/filesystem/dir-common.h (_Dir_base::_At_path): New class.
(_Dir_base::_Dir_Base, _Dir_base::openat): Use _At_path.
* src/filesystem/dir.cc (_Dir::dir_and_pathname): Replace with
current() returning _At_path.
(_Dir::_Dir, _Dir::open_subdir): Adjust.

(cherry picked from commit 198781144f33b0ef17dd2094580b5c77ad97d6e8)
libstdc++-v3/src/c++17/fs_dir.cc
libstdc++-v3/src/filesystem/dir-common.h
libstdc++-v3/src/filesystem/dir.cc
This page took 0.059943 seconds and 6 git commands to generate.