]> git.ipfire.org Git - thirdparty/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>
Tue, 28 Jun 2022 11:09:20 +0000 (12:09 +0100)
commit198781144f33b0ef17dd2094580b5c77ad97d6e8
treeea71d88cfa12271bebe5437f606e0981dc0cdaa3
parent835b19936bf30d693783bfa39145a4ce243bbd7c
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 tiughtly 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.
libstdc++-v3/src/c++17/fs_dir.cc
libstdc++-v3/src/filesystem/dir-common.h
libstdc++-v3/src/filesystem/dir.cc