Commit bb52a7e3 by Jonathan Wakely Committed by Jonathan Wakely

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.

From-SVN: r241486
parent cfef9c1e
2016-10-24 Jonathan Wakely <jwakely@redhat.com> 2016-10-24 Jonathan Wakely <jwakely@redhat.com>
* 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.
* src/filesystem/ops.cc (close_fd): Remove. * src/filesystem/ops.cc (close_fd): Remove.
(do_copy_file): Just use close(3) instead of close_fd, to prevent (do_copy_file): Just use close(3) instead of close_fd, to prevent
retrying on error. retrying on error.
......
...@@ -79,8 +79,7 @@ namespace ...@@ -79,8 +79,7 @@ namespace
return (obj & bits) != Bitmask::none; return (obj & bits) != Bitmask::none;
} }
// Returns {dirp, p} on success, {nullptr, p} on error. // Returns {dirp, p} on success, {} on error (whether ignored or not).
// If an ignored EACCES error occurs returns {}.
inline fs::_Dir inline fs::_Dir
open_dir(const fs::path& p, fs::directory_options options, open_dir(const fs::path& p, fs::directory_options options,
std::error_code* ec) std::error_code* ec)
...@@ -102,7 +101,7 @@ namespace ...@@ -102,7 +101,7 @@ namespace
std::error_code(err, std::generic_category()))); std::error_code(err, std::generic_category())));
ec->assign(err, std::generic_category()); ec->assign(err, std::generic_category());
return {nullptr, p}; return {};
} }
inline fs::file_type inline fs::file_type
...@@ -169,7 +168,7 @@ fs::_Dir::advance(error_code* ec, directory_options options) ...@@ -169,7 +168,7 @@ fs::_Dir::advance(error_code* ec, directory_options options)
"directory iterator cannot advance", "directory iterator cannot advance",
std::error_code(err, std::generic_category()))); std::error_code(err, std::generic_category())));
ec->assign(err, std::generic_category()); ec->assign(err, std::generic_category());
return true; return false;
} }
else else
{ {
...@@ -191,12 +190,6 @@ directory_iterator(const path& p, directory_options options, error_code* ec) ...@@ -191,12 +190,6 @@ directory_iterator(const path& p, directory_options options, error_code* ec)
if (sp->advance(ec, options)) if (sp->advance(ec, options))
_M_dir.swap(sp); _M_dir.swap(sp);
} }
else if (!dir.path.empty())
{
// An error occurred, we need a non-empty shared_ptr so that *this will
// not compare equal to the end iterator.
_M_dir.reset(static_cast<fs::_Dir*>(nullptr));
}
} }
const fs::directory_entry& const fs::directory_entry&
...@@ -270,10 +263,6 @@ recursive_directory_iterator(const path& p, directory_options options, ...@@ -270,10 +263,6 @@ recursive_directory_iterator(const path& p, directory_options options,
std::error_code(err, std::generic_category()))); std::error_code(err, std::generic_category())));
ec->assign(err, std::generic_category()); ec->assign(err, std::generic_category());
// An error occurred, we need a non-empty shared_ptr so that *this will
// not compare equal to the end iterator.
_M_dirs.reset(static_cast<_Dir_stack*>(nullptr));
} }
} }
......
...@@ -34,7 +34,7 @@ test01() ...@@ -34,7 +34,7 @@ test01()
const auto p = __gnu_test::nonexistent_path(); const auto p = __gnu_test::nonexistent_path();
fs::directory_iterator iter(p, ec); fs::directory_iterator iter(p, ec);
VERIFY( ec ); VERIFY( ec );
VERIFY( iter != fs::directory_iterator() ); VERIFY( iter == fs::directory_iterator() );
// Test empty directory. // Test empty directory.
create_directory(p, fs::current_path(), ec); create_directory(p, fs::current_path(), ec);
...@@ -58,7 +58,7 @@ test01() ...@@ -58,7 +58,7 @@ test01()
VERIFY( !ec ); VERIFY( !ec );
iter = fs::directory_iterator(p, ec); iter = fs::directory_iterator(p, ec);
VERIFY( ec ); VERIFY( ec );
VERIFY( iter != fs::directory_iterator() ); VERIFY( iter == fs::directory_iterator() );
// Test inaccessible directory, skipping permission denied. // Test inaccessible directory, skipping permission denied.
const auto opts = fs::directory_options::skip_permission_denied; const auto opts = fs::directory_options::skip_permission_denied;
......
...@@ -34,7 +34,7 @@ test01() ...@@ -34,7 +34,7 @@ test01()
const auto p = __gnu_test::nonexistent_path(); const auto p = __gnu_test::nonexistent_path();
fs::recursive_directory_iterator iter(p, ec); fs::recursive_directory_iterator iter(p, ec);
VERIFY( ec ); VERIFY( ec );
VERIFY( iter != fs::recursive_directory_iterator() ); VERIFY( iter == fs::recursive_directory_iterator() );
// Test empty directory. // Test empty directory.
create_directory(p, fs::current_path(), ec); create_directory(p, fs::current_path(), ec);
...@@ -60,7 +60,7 @@ test01() ...@@ -60,7 +60,7 @@ test01()
VERIFY( !ec ); VERIFY( !ec );
iter = fs::recursive_directory_iterator(p, ec); iter = fs::recursive_directory_iterator(p, ec);
VERIFY( ec ); VERIFY( ec );
VERIFY( iter != fs::recursive_directory_iterator() ); VERIFY( iter == fs::recursive_directory_iterator() );
// Test inaccessible directory, skipping permission denied. // Test inaccessible directory, skipping permission denied.
const auto opts = fs::directory_options::skip_permission_denied; const auto opts = fs::directory_options::skip_permission_denied;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment