forked from OSchip/llvm-project
Recommit "Use possibly cached directory entry values when performing recursive directory iteration."
The initial patch didn't correctly handle systems when the dirent struct didn't provide the d_type member. Specifically it set the cache to the incorrect state, and claimed it was partially populated. The updated version of this change correctly handles setting up the cache when the file type is not known (aka file_type::none). llvm-svn: 337765
This commit is contained in:
parent
82d975afa0
commit
f96de02960
|
@ -2200,8 +2200,16 @@ private:
|
|||
static __cached_data __create_iter_result(file_type __ft) {
|
||||
__cached_data __data;
|
||||
__data.__type_ = __ft;
|
||||
__data.__cache_type_ =
|
||||
__ft == file_type::symlink ? _IterSymlink : _IterNonSymlink;
|
||||
__data.__cache_type_ = [&]() {
|
||||
switch (__ft) {
|
||||
case file_type::none:
|
||||
return _Empty;
|
||||
case file_type::symlink:
|
||||
return _IterSymlink;
|
||||
default:
|
||||
return _IterNonSymlink;
|
||||
}
|
||||
}();
|
||||
return __data;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,10 @@ static file_type get_file_type(DirEntT *ent, int) {
|
|||
}
|
||||
return file_type::none;
|
||||
}
|
||||
|
||||
template <class DirEntT>
|
||||
static file_type get_file_type(DirEntT *ent, long) {
|
||||
return file_type::unknown;
|
||||
return file_type::none;
|
||||
}
|
||||
|
||||
static pair<string_view, file_type>
|
||||
|
@ -359,13 +360,13 @@ bool recursive_directory_iterator::__try_recursion(error_code *ec) {
|
|||
bool skip_rec = false;
|
||||
error_code m_ec;
|
||||
if (!rec_sym) {
|
||||
file_status st = curr_it.__entry_.symlink_status(m_ec);
|
||||
file_status st(curr_it.__entry_.__get_sym_ft(&m_ec));
|
||||
if (m_ec && status_known(st))
|
||||
m_ec.clear();
|
||||
if (m_ec || is_symlink(st) || !is_directory(st))
|
||||
skip_rec = true;
|
||||
} else {
|
||||
file_status st = curr_it.__entry_.status(m_ec);
|
||||
file_status st(curr_it.__entry_.__get_ft(&m_ec));
|
||||
if (m_ec && status_known(st))
|
||||
m_ec.clear();
|
||||
if (m_ec || !is_directory(st))
|
||||
|
|
Loading…
Reference in New Issue