Commit 4fbdbaaa authored by Istiaque Ahmed's avatar Istiaque Ahmed Committed by Commit Bot

[CV] Switch locales check to use relative paths.

This changes ContentVerifier::ShouldVerifyAnyPath to work with
relative paths, instead of constructing full paths.

This should help in using "canonical" paths in content verifier
code. "canonical" paths shouldn't be used as full paths as it
isn't safe to to do so on windows. Canonicalization lowercases
paths on windows, but for full paths with drive letters, that
doesn't seem immediately right. So this CL just make the
code in question work with relative paths, which shouldn't
need to worry about these caveats.

Also, fullpath length is strictly larger than relative path, this
gives marginal win.

Bug: 796395
Test: No behavior changes expected.
Change-Id: I924768805a61726f04ab4c1d64880fb326d8bf47
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2035497Reviewed-by: default avatarOleg Davydov <burunduk@chromium.org>
Commit-Queue: Istiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739409}
parent 5eab49a3
...@@ -687,11 +687,11 @@ bool ContentVerifier::ShouldVerifyAnyPaths( ...@@ -687,11 +687,11 @@ bool ContentVerifier::ShouldVerifyAnyPaths(
const std::set<base::FilePath>& background_or_content_paths = const std::set<base::FilePath>& background_or_content_paths =
*(data->background_or_content_paths); *(data->background_or_content_paths);
base::FilePath locales_dir = extension_root.Append(kLocaleFolder);
std::unique_ptr<std::set<std::string>> all_locales; std::unique_ptr<std::set<std::string>> all_locales;
const base::FilePath manifest_file(kManifestFilename); const base::FilePath manifest_file(kManifestFilename);
const base::FilePath messages_file(kMessagesFilename); const base::FilePath messages_file(kMessagesFilename);
const base::FilePath locales_relative_dir(kLocaleFolder);
for (const base::FilePath& relative_unix_path : relative_unix_paths) { for (const base::FilePath& relative_unix_path : relative_unix_paths) {
if (relative_unix_path.empty()) if (relative_unix_path.empty())
continue; continue;
...@@ -713,13 +713,13 @@ bool ContentVerifier::ShouldVerifyAnyPaths( ...@@ -713,13 +713,13 @@ bool ContentVerifier::ShouldVerifyAnyPaths(
if (base::Contains(browser_images, relative_unix_path)) if (base::Contains(browser_images, relative_unix_path))
continue; continue;
base::FilePath full_path = base::FilePath relative_path = relative_unix_path.NormalizePathSeparators();
extension_root.Append(relative_unix_path.NormalizePathSeparators()); base::FilePath full_path = extension_root.Append(relative_path);
if (full_path == file_util::GetIndexedRulesetPath(extension_root)) if (full_path == file_util::GetIndexedRulesetPath(extension_root))
continue; continue;
if (locales_dir.IsParent(full_path)) { if (locales_relative_dir.IsParent(relative_path)) {
if (!all_locales) { if (!all_locales) {
// TODO(asargent) - see if we can cache this list longer to avoid // TODO(asargent) - see if we can cache this list longer to avoid
// having to fetch it more than once for a given run of the // having to fetch it more than once for a given run of the
...@@ -732,10 +732,10 @@ bool ContentVerifier::ShouldVerifyAnyPaths( ...@@ -732,10 +732,10 @@ bool ContentVerifier::ShouldVerifyAnyPaths(
// Since message catalogs get transcoded during installation, we want // Since message catalogs get transcoded during installation, we want
// to skip those paths. See if this path looks like // to skip those paths. See if this path looks like
// _locales/<some locale>/messages.json - if so then skip it. // _locales/<some locale>/messages.json - if so then skip it.
if (full_path.BaseName() == messages_file && if (relative_path.BaseName() == messages_file &&
full_path.DirName().DirName() == locales_dir && relative_path.DirName().DirName() == locales_relative_dir &&
base::Contains(*all_locales, base::Contains(*all_locales,
full_path.DirName().BaseName().MaybeAsASCII())) { relative_path.DirName().BaseName().MaybeAsASCII())) {
continue; continue;
} }
} }
......
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