Commit 4051ddff authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Switch to 1-parameter version of base::DeleteFile() in extensions/.

The 1-parameter version is simpler, and the 2-parameter version is
deprecated.

Bug: 1009837
Change-Id: I74f7c0697d077d5cdea3501a86a558911762e3ee
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2284366Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786039}
parent 77c07452
...@@ -218,8 +218,8 @@ TEST_F(FileSequenceHelperTest, IndexedRulesetDeleted) { ...@@ -218,8 +218,8 @@ TEST_F(FileSequenceHelperTest, IndexedRulesetDeleted) {
// Now delete the first and third indexed rulesets. This would cause a // Now delete the first and third indexed rulesets. This would cause a
// re-index. // re-index.
base::DeleteFile(test_cases[0].source.indexed_path(), false /* recursive */); base::DeleteFile(test_cases[0].source.indexed_path());
base::DeleteFile(test_cases[2].source.indexed_path(), false /* recursive */); base::DeleteFile(test_cases[2].source.indexed_path());
test_cases[0].expected_result.reindexing_successful = true; test_cases[0].expected_result.reindexing_successful = true;
test_cases[2].expected_result.reindexing_successful = true; test_cases[2].expected_result.reindexing_successful = true;
...@@ -276,10 +276,10 @@ TEST_F(FileSequenceHelperTest, JSONAndIndexedRulesetDeleted) { ...@@ -276,10 +276,10 @@ TEST_F(FileSequenceHelperTest, JSONAndIndexedRulesetDeleted) {
TestLoadRulesets(test_cases); TestLoadRulesets(test_cases);
base::DeleteFile(test_cases[0].source.json_path(), false /* recursive */); base::DeleteFile(test_cases[0].source.json_path());
base::DeleteFile(test_cases[1].source.json_path(), false /* recursive */); base::DeleteFile(test_cases[1].source.json_path());
base::DeleteFile(test_cases[0].source.indexed_path(), false /* recursive */); base::DeleteFile(test_cases[0].source.indexed_path());
base::DeleteFile(test_cases[1].source.indexed_path(), false /* recursive */); base::DeleteFile(test_cases[1].source.indexed_path());
// Reindexing will fail since the JSON ruleset is now deleted. // Reindexing will fail since the JSON ruleset is now deleted.
test_cases[0].expected_result.reindexing_successful = false; test_cases[0].expected_result.reindexing_successful = false;
...@@ -299,8 +299,8 @@ TEST_F(FileSequenceHelperTest, UpdateDynamicRules) { ...@@ -299,8 +299,8 @@ TEST_F(FileSequenceHelperTest, UpdateDynamicRules) {
// Simulate adding rules for the first time i.e. with no JSON and indexed // Simulate adding rules for the first time i.e. with no JSON and indexed
// ruleset files. // ruleset files.
RulesetSource source = CreateTemporarySource(); RulesetSource source = CreateTemporarySource();
base::DeleteFile(source.json_path(), false /* recursive */); base::DeleteFile(source.json_path());
base::DeleteFile(source.indexed_path(), false /* recursive */); base::DeleteFile(source.indexed_path());
// Test success. // Test success.
std::vector<api::declarative_net_request::Rule> api_rules; std::vector<api::declarative_net_request::Rule> api_rules;
......
...@@ -51,8 +51,7 @@ std::unique_ptr<VerifiedContents> ReadVerifiedContents( ...@@ -51,8 +51,7 @@ std::unique_ptr<VerifiedContents> ReadVerifiedContents(
std::unique_ptr<VerifiedContents> verified_contents = std::unique_ptr<VerifiedContents> verified_contents =
VerifiedContents::Create(key.verifier_key, verified_contents_path); VerifiedContents::Create(key.verifier_key, verified_contents_path);
if (!verified_contents) { if (!verified_contents) {
if (delete_invalid_file && if (delete_invalid_file && !base::DeleteFile(verified_contents_path)) {
!base::DeleteFile(verified_contents_path, false)) {
LOG(WARNING) << "Failed to delete " << verified_contents_path.value(); LOG(WARNING) << "Failed to delete " << verified_contents_path.value();
} }
return nullptr; return nullptr;
......
...@@ -156,7 +156,7 @@ class ContentVerifyJobUnittest : public ExtensionsTest { ...@@ -156,7 +156,7 @@ class ContentVerifyJobUnittest : public ExtensionsTest {
observer.WaitForOnHashesReady(); observer.WaitForOnHashesReady();
run_content_read_step(verify_job.get(), &resource_contents); run_content_read_step(verify_job.get(), &resource_contents);
break; break;
}; }
return observer.WaitForJobFinished(); return observer.WaitForJobFinished();
} }
...@@ -280,8 +280,7 @@ TEST_F(ContentVerifyJobUnittest, DeletedAndMissingFiles) { ...@@ -280,8 +280,7 @@ TEST_F(ContentVerifyJobUnittest, DeletedAndMissingFiles) {
{ {
// Once background.js is deleted, verification will result in HASH_MISMATCH. // Once background.js is deleted, verification will result in HASH_MISMATCH.
// Delete the existent file first. // Delete the existent file first.
EXPECT_TRUE( EXPECT_TRUE(base::DeleteFile(unzipped_path.Append(existent_resource_path)));
base::DeleteFile(unzipped_path.Append(existent_resource_path), false));
// Deleted file will serve empty contents. // Deleted file will serve empty contents.
std::string empty_contents; std::string empty_contents;
...@@ -361,8 +360,7 @@ void WriteIncorrectComputedHashes(const base::FilePath& extension_path, ...@@ -361,8 +360,7 @@ void WriteIncorrectComputedHashes(const base::FilePath& extension_path,
ASSERT_TRUE( ASSERT_TRUE(
base::PathExists(file_util::GetComputedHashesPath(extension_path))); base::PathExists(file_util::GetComputedHashesPath(extension_path)));
base::DeleteFile(file_util::GetComputedHashesPath(extension_path), base::DeleteFile(file_util::GetComputedHashesPath(extension_path));
false /* recursive */);
int block_size = extension_misc::kContentVerificationDefaultBlockSize; int block_size = extension_misc::kContentVerificationDefaultBlockSize;
ComputedHashes::Data incorrect_computed_hashes_data; ComputedHashes::Data incorrect_computed_hashes_data;
...@@ -386,8 +384,7 @@ void WriteEmptyComputedHashes(const base::FilePath& extension_path) { ...@@ -386,8 +384,7 @@ void WriteEmptyComputedHashes(const base::FilePath& extension_path) {
ASSERT_TRUE( ASSERT_TRUE(
base::PathExists(file_util::GetComputedHashesPath(extension_path))); base::PathExists(file_util::GetComputedHashesPath(extension_path)));
base::DeleteFile(file_util::GetComputedHashesPath(extension_path), base::DeleteFile(file_util::GetComputedHashesPath(extension_path));
false /* recursive */);
ComputedHashes::Data incorrect_computed_hashes_data; ComputedHashes::Data incorrect_computed_hashes_data;
...@@ -418,7 +415,7 @@ TEST_F(ContentVerifyJobUnittest, DeletedResourceAndCorruptedComputedHashes) { ...@@ -418,7 +415,7 @@ TEST_F(ContentVerifyJobUnittest, DeletedResourceAndCorruptedComputedHashes) {
base::FilePath unzipped_path = temp_dir.GetPath(); base::FilePath unzipped_path = temp_dir.GetPath();
WriteIncorrectComputedHashes(unzipped_path, resource_path); WriteIncorrectComputedHashes(unzipped_path, resource_path);
EXPECT_TRUE( EXPECT_TRUE(
base::DeleteFile(unzipped_path.Append(base::FilePath(kResource)), false)); base::DeleteFile(unzipped_path.Append(base::FilePath(kResource))));
content_verifier()->ClearCacheForTesting(); content_verifier()->ClearCacheForTesting();
{ {
...@@ -451,7 +448,7 @@ TEST_F(ContentVerifyJobUnittest, DeletedResourceAndCleanedComputedHashes) { ...@@ -451,7 +448,7 @@ TEST_F(ContentVerifyJobUnittest, DeletedResourceAndCleanedComputedHashes) {
base::FilePath unzipped_path = temp_dir.GetPath(); base::FilePath unzipped_path = temp_dir.GetPath();
WriteEmptyComputedHashes(unzipped_path); WriteEmptyComputedHashes(unzipped_path);
EXPECT_TRUE( EXPECT_TRUE(
base::DeleteFile(unzipped_path.Append(base::FilePath(kResource)), false)); base::DeleteFile(unzipped_path.Append(base::FilePath(kResource))));
content_verifier()->ClearCacheForTesting(); content_verifier()->ClearCacheForTesting();
{ {
...@@ -600,8 +597,7 @@ TEST_F(ContentVerifyJobWithoutSignedHashesUnittest, ComputedHashesLoad) { ...@@ -600,8 +597,7 @@ TEST_F(ContentVerifyJobWithoutSignedHashesUnittest, ComputedHashesLoad) {
{ {
// Case where computed_hashes.json doesn't exist. // Case where computed_hashes.json doesn't exist.
base::DeleteFile(file_util::GetComputedHashesPath(unzipped_path), base::DeleteFile(file_util::GetComputedHashesPath(unzipped_path));
false /* recursive */);
TestContentVerifySingleJobObserver observer(extension->id(), kResourcePath); TestContentVerifySingleJobObserver observer(extension->id(), kResourcePath);
content_verifier()->ClearCacheForTesting(); content_verifier()->ClearCacheForTesting();
......
...@@ -280,7 +280,7 @@ bool ExtensionCreator::Run(const base::FilePath& extension_dir, ...@@ -280,7 +280,7 @@ bool ExtensionCreator::Run(const base::FilePath& extension_dir,
result = true; result = true;
} }
base::DeleteFile(zip_path, false); base::DeleteFile(zip_path);
return result; return result;
} }
......
...@@ -34,7 +34,7 @@ std::tuple<std::vector<uint8_t>, bool, bool> ReadAndDeleteBinaryFile( ...@@ -34,7 +34,7 @@ std::tuple<std::vector<uint8_t>, bool, bool> ReadAndDeleteBinaryFile(
base::ReadFile(path, reinterpret_cast<char*>(contents.data()), base::ReadFile(path, reinterpret_cast<char*>(contents.data()),
file_size) == file_size; file_size) == file_size;
} }
bool delete_success = base::DeleteFile(path, /*recursive=*/false); bool delete_success = base::DeleteFile(path);
return std::make_tuple(std::move(contents), read_success, delete_success); return std::make_tuple(std::move(contents), read_success, delete_success);
} }
......
...@@ -22,7 +22,7 @@ std::tuple<std::string, bool, bool> ReadAndDeleteTextFile( ...@@ -22,7 +22,7 @@ std::tuple<std::string, bool, bool> ReadAndDeleteTextFile(
const base::FilePath& path) { const base::FilePath& path) {
std::string contents; std::string contents;
bool read_success = base::ReadFileToString(path, &contents); bool read_success = base::ReadFileToString(path, &contents);
bool delete_success = base::DeleteFile(path, /*recursive=*/false); bool delete_success = base::DeleteFile(path);
return std::make_tuple(contents, read_success, delete_success); return std::make_tuple(contents, read_success, delete_success);
} }
......
...@@ -76,7 +76,7 @@ bool VerifyJunctionFreeLocation(base::FilePath* temp_dir) { ...@@ -76,7 +76,7 @@ bool VerifyJunctionFreeLocation(base::FilePath* temp_dir) {
// If you change the exit points of this function please make sure all // If you change the exit points of this function please make sure all
// exit points delete this temp file! // exit points delete this temp file!
if (base::WriteFile(temp_file, ".", 1) != 1) { if (base::WriteFile(temp_file, ".", 1) != 1) {
base::DeleteFile(temp_file, false); base::DeleteFile(temp_file);
return false; return false;
} }
...@@ -91,7 +91,7 @@ bool VerifyJunctionFreeLocation(base::FilePath* temp_dir) { ...@@ -91,7 +91,7 @@ bool VerifyJunctionFreeLocation(base::FilePath* temp_dir) {
} }
// Clean up the temp file. // Clean up the temp file.
base::DeleteFile(temp_file, false); base::DeleteFile(temp_file);
return normalized; return normalized;
} }
......
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