Commit a19cb04b authored by Fabrice de Gans-Riberi's avatar Fabrice de Gans-Riberi Committed by Commit Bot

[fuchsia] Disable SymLinks tracking on Fuchsia.

By default, on POSIX, FileEnumerator keeps track of previously
visited directories by inode. On Fuchsia, this was not working
properly because all files under the /pkg directory have inode 1.

To work around this issue, the SHOW_SYM_LINKS flag was used. This flag
makes FileEnumerator always parse through SymLinks on POSIX platforms.

Since Fuchsia does not support SymLinks, this CL makes the
SHOW_SYM_LINKS flag have no effect on Fuchsia and tweaks the
FileEnumerator behavior to never keep track of inodes on Fuchsia.

Bug: 1033230
Change-Id: I2bb7a25b3e49f394323bfb14e1e5132dda92ca12
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1967970
Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738345}
parent 5019665f
...@@ -30,6 +30,26 @@ void GetStat(const FilePath& path, bool show_links, stat_wrapper_t* st) { ...@@ -30,6 +30,26 @@ void GetStat(const FilePath& path, bool show_links, stat_wrapper_t* st) {
} }
} }
#if defined(OS_FUCHSIA)
bool ShouldShowSymLinks(int file_type) {
return false;
}
#else
bool ShouldShowSymLinks(int file_type) {
return file_type & FileEnumerator::SHOW_SYM_LINKS;
}
#endif // defined(OS_FUCHSIA)
#if defined(OS_FUCHSIA)
bool ShouldTrackVisitedDirectories(int file_type) {
return false;
}
#else
bool ShouldTrackVisitedDirectories(int file_type) {
return !(file_type & FileEnumerator::SHOW_SYM_LINKS);
}
#endif // defined(OS_FUCHSIA)
} // namespace } // namespace
// FileEnumerator::FileInfo ---------------------------------------------------- // FileEnumerator::FileInfo ----------------------------------------------------
...@@ -89,7 +109,7 @@ FileEnumerator::FileEnumerator(const FilePath& root_path, ...@@ -89,7 +109,7 @@ FileEnumerator::FileEnumerator(const FilePath& root_path,
// INCLUDE_DOT_DOT must not be specified if recursive. // INCLUDE_DOT_DOT must not be specified if recursive.
DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_))); DCHECK(!(recursive && (INCLUDE_DOT_DOT & file_type_)));
if (recursive && !(file_type & SHOW_SYM_LINKS)) { if (recursive && ShouldTrackVisitedDirectories(file_type_)) {
stat_wrapper_t st; stat_wrapper_t st;
GetStat(root_path, false, &st); GetStat(root_path, false, &st);
visited_directories_.insert(st.st_ino); visited_directories_.insert(st.st_ino);
...@@ -160,15 +180,14 @@ FilePath FileEnumerator::Next() { ...@@ -160,15 +180,14 @@ FilePath FileEnumerator::Next() {
continue; continue;
const FilePath full_path = root_path_.Append(info.filename_); const FilePath full_path = root_path_.Append(info.filename_);
const bool show_sym_links = file_type_ & SHOW_SYM_LINKS; GetStat(full_path, ShouldShowSymLinks(file_type_), &info.stat_);
GetStat(full_path, show_sym_links, &info.stat_);
const bool is_dir = info.IsDirectory(); const bool is_dir = info.IsDirectory();
// Recursive mode: schedule traversal of a directory if either // Recursive mode: schedule traversal of a directory if either
// SHOW_SYM_LINKS is on or we haven't visited the directory yet. // SHOW_SYM_LINKS is on or we haven't visited the directory yet.
if (recursive_ && is_dir && if (recursive_ && is_dir &&
(show_sym_links || (!ShouldTrackVisitedDirectories(file_type_) ||
visited_directories_.insert(info.stat_.st_ino).second)) { visited_directories_.insert(info.stat_.st_ino).second)) {
pending_paths_.push(full_path); pending_paths_.push(full_path);
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "build/build_config.h"
#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
using base::FilePath; using base::FilePath;
...@@ -20,13 +19,8 @@ namespace quic { ...@@ -20,13 +19,8 @@ namespace quic {
std::vector<std::string> ReadFileContentsImpl(const std::string& dirname) { std::vector<std::string> ReadFileContentsImpl(const std::string& dirname) {
std::vector<std::string> files; std::vector<std::string> files;
FilePath directory(FilePath::FromUTF8Unsafe(dirname)); FilePath directory(FilePath::FromUTF8Unsafe(dirname));
int file_type = base::FileEnumerator::FILES; base::FileEnumerator file_list(directory, true /* recursive */,
#if defined(OS_FUCHSIA) base::FileEnumerator::FILES);
// TODO(crbug.com): Fix FileEnumerator to correctly recurse into
// subdirectories contained in bundles.
file_type |= base::FileEnumerator::SHOW_SYM_LINKS;
#endif
base::FileEnumerator file_list(directory, /*recurse=*/true, file_type);
for (FilePath file_iter = file_list.Next(); !file_iter.empty(); for (FilePath file_iter = file_list.Next(); !file_iter.empty();
file_iter = file_list.Next()) { file_iter = file_list.Next()) {
files.push_back(file_iter.AsUTF8Unsafe()); files.push_back(file_iter.AsUTF8Unsafe());
......
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