diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-24 11:30:15 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-10-30 12:56:19 +0000 |
commit | 6036726eb981b6c4b42047513b9d3f4ac865daac (patch) | |
tree | 673593e70678e7789766d1f732eb51f613a2703b /chromium/base/files | |
parent | 466052c4e7c052268fd931888cd58961da94c586 (diff) | |
download | qtwebengine-chromium-6036726eb981b6c4b42047513b9d3f4ac865daac.tar.gz |
BASELINE: Update Chromium to 70.0.3538.78
Change-Id: Ie634710bf039e26c1957f4ae45e101bd4c434ae7
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/base/files')
-rw-r--r-- | chromium/base/files/file_enumerator.h | 5 | ||||
-rw-r--r-- | chromium/base/files/file_enumerator_posix.cc | 16 | ||||
-rw-r--r-- | chromium/base/files/file_enumerator_unittest.cc | 32 | ||||
-rw-r--r-- | chromium/base/files/file_enumerator_win.cc | 2 | ||||
-rw-r--r-- | chromium/base/files/file_util_win.cc | 46 |
5 files changed, 73 insertions, 28 deletions
diff --git a/chromium/base/files/file_enumerator.h b/chromium/base/files/file_enumerator.h index 0fa99a68615..f09a7bae091 100644 --- a/chromium/base/files/file_enumerator.h +++ b/chromium/base/files/file_enumerator.h @@ -22,6 +22,7 @@ #elif defined(OS_POSIX) || defined(OS_FUCHSIA) #include <sys/stat.h> #include <unistd.h> +#include <unordered_set> #endif namespace base { @@ -153,6 +154,10 @@ class BASE_EXPORT FileEnumerator { // The files in the current directory std::vector<FileInfo> directory_entries_; + // Set of visited directories. Used to prevent infinite looping along + // circular symlinks. + std::unordered_set<ino_t> visited_directories_; + // The next entry to use from the directory_entries_ vector size_t current_directory_entry_; #endif diff --git a/chromium/base/files/file_enumerator_posix.cc b/chromium/base/files/file_enumerator_posix.cc index 4b429c64482..b817ca21d59 100644 --- a/chromium/base/files/file_enumerator_posix.cc +++ b/chromium/base/files/file_enumerator_posix.cc @@ -89,6 +89,12 @@ FileEnumerator::FileEnumerator(const FilePath& root_path, // INCLUDE_DOT_DOT must not be specified if recursive. DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_))); + if (recursive && !(file_type & SHOW_SYM_LINKS)) { + struct stat st; + GetStat(root_path, false, &st); + visited_directories_.insert(st.st_ino); + } + pending_paths_.push(root_path); } @@ -154,12 +160,18 @@ FilePath FileEnumerator::Next() { continue; const FilePath full_path = root_path_.Append(info.filename_); - GetStat(full_path, file_type_ & SHOW_SYM_LINKS, &info.stat_); + const bool show_sym_links = file_type_ & SHOW_SYM_LINKS; + GetStat(full_path, show_sym_links, &info.stat_); const bool is_dir = info.IsDirectory(); - if (recursive_ && is_dir) + // Recursive mode: schedule traversal of a directory if either + // SHOW_SYM_LINKS is on or we haven't visited the directory yet. + if (recursive_ && is_dir && + (show_sym_links || + visited_directories_.insert(info.stat_.st_ino).second)) { pending_paths_.push(full_path); + } if (is_pattern_matched && IsTypeMatched(is_dir)) directory_entries_.push_back(std::move(info)); diff --git a/chromium/base/files/file_enumerator_unittest.cc b/chromium/base/files/file_enumerator_unittest.cc index 11df075ecd6..cfe481660d9 100644 --- a/chromium/base/files/file_enumerator_unittest.cc +++ b/chromium/base/files/file_enumerator_unittest.cc @@ -11,6 +11,7 @@ #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" +#include "build/build_config.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -309,4 +310,35 @@ TEST(FileEnumerator, FilesInSubfoldersWithFiltering) { EXPECT_THAT(files, UnorderedElementsAre(subdir_foo, foo_foo, bar_foo)); } +#if defined(OS_POSIX) +TEST(FileEnumerator, SymLinkLoops) { + ScopedTempDir temp_dir; + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); + + const FilePath subdir = temp_dir.GetPath().AppendASCII("subdir"); + ASSERT_TRUE(CreateDirectory(subdir)); + + const FilePath file = subdir.AppendASCII("test.txt"); + ASSERT_TRUE(CreateDummyFile(file)); + + const FilePath link = subdir.AppendASCII("link"); + ASSERT_TRUE(CreateSymbolicLink(temp_dir.GetPath(), link)); + + auto files = RunEnumerator( + temp_dir.GetPath(), true, + FileEnumerator::FILES | FileEnumerator::DIRECTORIES, kEmptyPattern, + FileEnumerator::FolderSearchPolicy::MATCH_ONLY); + + EXPECT_THAT(files, UnorderedElementsAre(subdir, link, file)); + + files = RunEnumerator(subdir, true, + FileEnumerator::FILES | FileEnumerator::DIRECTORIES | + FileEnumerator::SHOW_SYM_LINKS, + kEmptyPattern, + FileEnumerator::FolderSearchPolicy::MATCH_ONLY); + + EXPECT_THAT(files, UnorderedElementsAre(link, file)); +} +#endif + } // namespace base diff --git a/chromium/base/files/file_enumerator_win.cc b/chromium/base/files/file_enumerator_win.cc index f96074cec43..6d8e3266578 100644 --- a/chromium/base/files/file_enumerator_win.cc +++ b/chromium/base/files/file_enumerator_win.cc @@ -4,12 +4,12 @@ #include "base/files/file_enumerator.h" -#include <shlwapi.h> #include <stdint.h> #include <string.h> #include "base/logging.h" #include "base/threading/thread_restrictions.h" +#include "base/win/shlwapi.h" namespace base { diff --git a/chromium/base/files/file_util_win.cc b/chromium/base/files/file_util_win.cc index e81757f8f99..6ae2331985c 100644 --- a/chromium/base/files/file_util_win.cc +++ b/chromium/base/files/file_util_win.cc @@ -598,8 +598,8 @@ bool CreateDirectoryAndGetError(const FilePath& full_path, AssertBlockingAllowed(); // If the path exists, we've succeeded if it's a directory, failed otherwise. - const wchar_t* full_path_str = full_path.value().c_str(); - DWORD fileattr = ::GetFileAttributes(full_path_str); + const wchar_t* const full_path_str = full_path.value().c_str(); + const DWORD fileattr = ::GetFileAttributes(full_path_str); if (fileattr != INVALID_FILE_ATTRIBUTES) { if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0) { DVLOG(1) << "CreateDirectory(" << full_path_str << "), " @@ -608,9 +608,9 @@ bool CreateDirectoryAndGetError(const FilePath& full_path, } DLOG(WARNING) << "CreateDirectory(" << full_path_str << "), " << "conflicts with existing file."; - if (error) { + if (error) *error = File::FILE_ERROR_NOT_A_DIRECTORY; - } + ::SetLastError(ERROR_FILE_EXISTS); return false; } @@ -621,37 +621,33 @@ bool CreateDirectoryAndGetError(const FilePath& full_path, // directories starting with the highest-level missing parent. FilePath parent_path(full_path.DirName()); if (parent_path.value() == full_path.value()) { - if (error) { + if (error) *error = File::FILE_ERROR_NOT_FOUND; - } + ::SetLastError(ERROR_FILE_NOT_FOUND); return false; } if (!CreateDirectoryAndGetError(parent_path, error)) { DLOG(WARNING) << "Failed to create one of the parent directories."; - if (error) { - DCHECK(*error != File::FILE_OK); - } + DCHECK(!error || *error != File::FILE_OK); return false; } - if (!::CreateDirectory(full_path_str, NULL)) { - DWORD error_code = ::GetLastError(); - if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { - // This error code ERROR_ALREADY_EXISTS doesn't indicate whether we - // were racing with someone creating the same directory, or a file - // with the same path. If DirectoryExists() returns true, we lost the - // race to create the same directory. - return true; - } else { - if (error) - *error = File::OSErrorToFileError(error_code); - DLOG(WARNING) << "Failed to create directory " << full_path_str - << ", last error is " << error_code << "."; - return false; - } - } else { + if (::CreateDirectory(full_path_str, NULL)) + return true; + + const DWORD error_code = ::GetLastError(); + if (error_code == ERROR_ALREADY_EXISTS && DirectoryExists(full_path)) { + // This error code ERROR_ALREADY_EXISTS doesn't indicate whether we were + // racing with someone creating the same directory, or a file with the same + // path. If DirectoryExists() returns true, we lost the race to create the + // same directory. return true; } + if (error) + *error = File::OSErrorToFileError(error_code); + ::SetLastError(error_code); + DPLOG(WARNING) << "Failed to create directory " << full_path_str; + return false; } bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { |