Commit 0c8b5443 authored by Lei Zhang's avatar Lei Zhang Committed by Commit Bot

Switch to 1-param version of base::DeleteFile() in base/ and chromeos/.

The 1-parameter version is simpler, and the 2-parameter version is
deprecated. Fix a few lint errors along the way.

Bug: 1009837
Change-Id: I01943e6090fa4103f7464f5d01f4003af9f5948e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2285918Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786178}
parent e8902701
...@@ -262,7 +262,7 @@ TEST_F(FilePathWatcherTest, DeletedFile) { ...@@ -262,7 +262,7 @@ TEST_F(FilePathWatcherTest, DeletedFile) {
ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false));
// Now make sure we get notified if the file is deleted. // Now make sure we get notified if the file is deleted.
base::DeleteFile(test_file(), false); base::DeleteFile(test_file());
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
...@@ -343,7 +343,7 @@ TEST_F(FilePathWatcherTest, NonExistentDirectory) { ...@@ -343,7 +343,7 @@ TEST_F(FilePathWatcherTest, NonExistentDirectory) {
VLOG(1) << "Waiting for file change"; VLOG(1) << "Waiting for file change";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
ASSERT_TRUE(base::DeleteFile(file, false)); ASSERT_TRUE(base::DeleteFile(file));
VLOG(1) << "Waiting for file deletion"; VLOG(1) << "Waiting for file deletion";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
...@@ -400,7 +400,7 @@ TEST_F(FilePathWatcherTest, DeleteAndRecreate) { ...@@ -400,7 +400,7 @@ TEST_F(FilePathWatcherTest, DeleteAndRecreate) {
std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector())); std::unique_ptr<TestDelegate> delegate(new TestDelegate(collector()));
ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false)); ASSERT_TRUE(SetupWatch(test_file(), &watcher, delegate.get(), false));
ASSERT_TRUE(base::DeleteFile(test_file(), false)); ASSERT_TRUE(base::DeleteFile(test_file()));
VLOG(1) << "Waiting for file deletion"; VLOG(1) << "Waiting for file deletion";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
...@@ -432,7 +432,7 @@ TEST_F(FilePathWatcherTest, WatchDirectory) { ...@@ -432,7 +432,7 @@ TEST_F(FilePathWatcherTest, WatchDirectory) {
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
#endif // !OS_MACOSX #endif // !OS_MACOSX
ASSERT_TRUE(base::DeleteFile(file1, false)); ASSERT_TRUE(base::DeleteFile(file1));
VLOG(1) << "Waiting for file1 deletion"; VLOG(1) << "Waiting for file1 deletion";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
...@@ -532,11 +532,11 @@ TEST_F(FilePathWatcherTest, RecursiveWatch) { ...@@ -532,11 +532,11 @@ TEST_F(FilePathWatcherTest, RecursiveWatch) {
#endif #endif
// Delete "$dir/subdir/subdir_file1". // Delete "$dir/subdir/subdir_file1".
ASSERT_TRUE(base::DeleteFile(subdir_file1, false)); ASSERT_TRUE(base::DeleteFile(subdir_file1));
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
// Delete "$dir/subdir/subdir_child_dir/child_dir_file1". // Delete "$dir/subdir/subdir_child_dir/child_dir_file1".
ASSERT_TRUE(base::DeleteFile(child_dir_file1, false)); ASSERT_TRUE(base::DeleteFile(child_dir_file1));
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
...@@ -576,7 +576,7 @@ TEST_F(FilePathWatcherTest, RecursiveWithSymLink) { ...@@ -576,7 +576,7 @@ TEST_F(FilePathWatcherTest, RecursiveWithSymLink) {
// Link change. // Link change.
FilePath target2(temp_dir_.GetPath().AppendASCII("target2")); FilePath target2(temp_dir_.GetPath().AppendASCII("target2"));
ASSERT_TRUE(base::CreateDirectory(target2)); ASSERT_TRUE(base::CreateDirectory(target2));
ASSERT_TRUE(base::DeleteFile(symlink, false)); ASSERT_TRUE(base::DeleteFile(symlink));
ASSERT_TRUE(base::CreateSymbolicLink(target2, symlink)); ASSERT_TRUE(base::CreateSymbolicLink(target2, symlink));
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
...@@ -658,7 +658,7 @@ TEST_F(FilePathWatcherTest, DeleteLink) { ...@@ -658,7 +658,7 @@ TEST_F(FilePathWatcherTest, DeleteLink) {
ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false));
// Now make sure we get notified if the link is deleted. // Now make sure we get notified if the link is deleted.
ASSERT_TRUE(base::DeleteFile(test_link(), false)); ASSERT_TRUE(base::DeleteFile(test_link()));
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
...@@ -702,7 +702,7 @@ TEST_F(FilePathWatcherTest, DeleteTargetLinkedFile) { ...@@ -702,7 +702,7 @@ TEST_F(FilePathWatcherTest, DeleteTargetLinkedFile) {
ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false)); ASSERT_TRUE(SetupWatch(test_link(), &watcher, delegate.get(), false));
// Now make sure we get notified if the target file is deleted. // Now make sure we get notified if the target file is deleted.
ASSERT_TRUE(base::DeleteFile(test_file(), false)); ASSERT_TRUE(base::DeleteFile(test_file()));
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
...@@ -729,7 +729,7 @@ TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) { ...@@ -729,7 +729,7 @@ TEST_F(FilePathWatcherTest, LinkedDirectoryPart1) {
VLOG(1) << "Waiting for file change"; VLOG(1) << "Waiting for file change";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
ASSERT_TRUE(base::DeleteFile(file, false)); ASSERT_TRUE(base::DeleteFile(file));
VLOG(1) << "Waiting for file deletion"; VLOG(1) << "Waiting for file deletion";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
...@@ -758,7 +758,7 @@ TEST_F(FilePathWatcherTest, LinkedDirectoryPart2) { ...@@ -758,7 +758,7 @@ TEST_F(FilePathWatcherTest, LinkedDirectoryPart2) {
VLOG(1) << "Waiting for file change"; VLOG(1) << "Waiting for file change";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
ASSERT_TRUE(base::DeleteFile(file, false)); ASSERT_TRUE(base::DeleteFile(file));
VLOG(1) << "Waiting for file deletion"; VLOG(1) << "Waiting for file deletion";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
...@@ -785,7 +785,7 @@ TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) { ...@@ -785,7 +785,7 @@ TEST_F(FilePathWatcherTest, LinkedDirectoryPart3) {
VLOG(1) << "Waiting for file change"; VLOG(1) << "Waiting for file change";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
ASSERT_TRUE(base::DeleteFile(file, false)); ASSERT_TRUE(base::DeleteFile(file));
VLOG(1) << "Waiting for file deletion"; VLOG(1) << "Waiting for file deletion";
ASSERT_TRUE(WaitForEvents()); ASSERT_TRUE(WaitForEvents());
} }
......
...@@ -26,20 +26,19 @@ namespace base { ...@@ -26,20 +26,19 @@ namespace base {
class FileHelper { class FileHelper {
public: public:
FileHelper(FileProxy* proxy, File file) FileHelper(FileProxy* proxy, File file)
: file_(std::move(file)), : file_(std::move(file)),
error_(File::FILE_ERROR_FAILED), error_(File::FILE_ERROR_FAILED),
task_runner_(proxy->task_runner()), task_runner_(proxy->task_runner()),
proxy_(AsWeakPtr(proxy)) { proxy_(AsWeakPtr(proxy)) {}
}
void PassFile() {
void PassFile() { if (proxy_)
if (proxy_) proxy_->SetFile(std::move(file_));
proxy_->SetFile(std::move(file_)); else if (file_.IsValid())
else if (file_.IsValid()) task_runner_->PostTask(FROM_HERE,
task_runner_->PostTask(FROM_HERE, BindOnce(&FileDeleter, std::move(file_)));
BindOnce(&FileDeleter, std::move(file_))); }
}
protected: protected:
File file_; File file_;
...@@ -134,7 +133,7 @@ class CreateTemporaryHelper : public FileHelper { ...@@ -134,7 +133,7 @@ class CreateTemporaryHelper : public FileHelper {
error_ = File::FILE_OK; error_ = File::FILE_OK;
} else { } else {
error_ = file_.error_details(); error_ = file_.error_details();
DeleteFile(file_path_, false); DeleteFile(file_path_);
file_path_.clear(); file_path_.clear();
} }
} }
......
...@@ -233,7 +233,7 @@ TEST_F(FileProxyTest, CreateTemporary) { ...@@ -233,7 +233,7 @@ TEST_F(FileProxyTest, CreateTemporary) {
// Try a few times because files may be locked by anti-virus or other. // Try a few times because files may be locked by anti-virus or other.
bool deleted_temp_file = false; bool deleted_temp_file = false;
for (int i = 0; !deleted_temp_file && i < 3; ++i) { for (int i = 0; !deleted_temp_file && i < 3; ++i) {
if (base::DeleteFile(path_, false)) if (base::DeleteFile(path_))
deleted_temp_file = true; deleted_temp_file = true;
else else
// Wait one second and then try again // Wait one second and then try again
......
...@@ -118,7 +118,7 @@ void DeleteTmpFileWithRetry(File tmp_file, ...@@ -118,7 +118,7 @@ void DeleteTmpFileWithRetry(File tmp_file,
static constexpr TimeDelta kDeleteFileRetryDelay = static constexpr TimeDelta kDeleteFileRetryDelay =
TimeDelta::FromMilliseconds(250); TimeDelta::FromMilliseconds(250);
if (!DeleteFile(tmp_file_path, /*recursive=*/false)) { if (!DeleteFile(tmp_file_path)) {
const auto last_file_error = File::GetLastFileError(); const auto last_file_error = File::GetLastFileError();
if (++attempt >= kMaxDeleteAttempts) { if (++attempt >= kMaxDeleteAttempts) {
// All retries have been exhausted; record the final error. // All retries have been exhausted; record the final error.
......
...@@ -160,7 +160,7 @@ bool ImportantFileWriterCleaner::CleanInBackground( ...@@ -160,7 +160,7 @@ bool ImportantFileWriterCleaner::CleanInBackground(
const FileEnumerator::FileInfo info = file_enum.GetInfo(); const FileEnumerator::FileInfo info = file_enum.GetInfo();
if (info.GetLastModifiedTime() >= upper_bound_time) if (info.GetLastModifiedTime() >= upper_bound_time)
continue; continue;
if (DeleteFile(path, /*recursive=*/false)) if (DeleteFile(path))
++successes; ++successes;
else else
++fails; ++fails;
......
...@@ -39,7 +39,7 @@ class MemoryMappedFileTest : public PlatformTest { ...@@ -39,7 +39,7 @@ class MemoryMappedFileTest : public PlatformTest {
CreateTemporaryFile(&temp_file_path_); CreateTemporaryFile(&temp_file_path_);
} }
void TearDown() override { EXPECT_TRUE(DeleteFile(temp_file_path_, false)); } void TearDown() override { EXPECT_TRUE(DeleteFile(temp_file_path_)); }
void CreateTemporaryTestFile(size_t size) { void CreateTemporaryTestFile(size_t size) {
File file(temp_file_path_, File file(temp_file_path_,
......
...@@ -207,8 +207,8 @@ class OpenFileTest : public OsValidationTest, ...@@ -207,8 +207,8 @@ class OpenFileTest : public OsValidationTest,
file_handle_.Close(); file_handle_.Close();
// Manually delete the temp files since the temp dir is reused across tests. // Manually delete the temp files since the temp dir is reused across tests.
ASSERT_TRUE(DeleteFile(temp_file_path_, false)); ASSERT_TRUE(DeleteFile(temp_file_path_));
ASSERT_TRUE(DeleteFile(temp_file_dest_path_, false)); ASSERT_TRUE(DeleteFile(temp_file_dest_path_));
} }
DWORD access() const { return access_; } DWORD access() const { return access_; }
......
...@@ -423,7 +423,7 @@ TEST_F(JSONFileValueSerializerTest, Roundtrip) { ...@@ -423,7 +423,7 @@ TEST_F(JSONFileValueSerializerTest, Roundtrip) {
// Now compare file contents. // Now compare file contents.
EXPECT_TRUE(TextContentsEqual(original_file_path, written_file_path)); EXPECT_TRUE(TextContentsEqual(original_file_path, written_file_path));
EXPECT_TRUE(DeleteFile(written_file_path, false)); EXPECT_TRUE(DeleteFile(written_file_path));
} }
TEST_F(JSONFileValueSerializerTest, RoundtripNested) { TEST_F(JSONFileValueSerializerTest, RoundtripNested) {
...@@ -449,7 +449,7 @@ TEST_F(JSONFileValueSerializerTest, RoundtripNested) { ...@@ -449,7 +449,7 @@ TEST_F(JSONFileValueSerializerTest, RoundtripNested) {
// Now compare file contents. // Now compare file contents.
EXPECT_TRUE(TextContentsEqual(original_file_path, written_file_path)); EXPECT_TRUE(TextContentsEqual(original_file_path, written_file_path));
EXPECT_TRUE(DeleteFile(written_file_path, false)); EXPECT_TRUE(DeleteFile(written_file_path));
} }
TEST_F(JSONFileValueSerializerTest, NoWhitespace) { TEST_F(JSONFileValueSerializerTest, NoWhitespace) {
......
...@@ -717,7 +717,7 @@ bool GlobalHistogramAllocator::CreateWithActiveFile(const FilePath& base_path, ...@@ -717,7 +717,7 @@ bool GlobalHistogramAllocator::CreateWithActiveFile(const FilePath& base_path,
StringPiece name) { StringPiece name) {
// Old "active" becomes "base". // Old "active" becomes "base".
if (!base::ReplaceFile(active_path, base_path, nullptr)) if (!base::ReplaceFile(active_path, base_path, nullptr))
base::DeleteFile(base_path, /*recursive=*/false); base::DeleteFile(base_path);
if (base::PathExists(active_path)) if (base::PathExists(active_path))
return false; return false;
...@@ -854,7 +854,7 @@ bool GlobalHistogramAllocator::CreateSpareFile(const FilePath& spare_path, ...@@ -854,7 +854,7 @@ bool GlobalHistogramAllocator::CreateSpareFile(const FilePath& spare_path,
success = ReplaceFile(temp_spare_path, spare_path, nullptr); success = ReplaceFile(temp_spare_path, spare_path, nullptr);
if (!success) if (!success)
DeleteFile(temp_spare_path, /*recursive=*/false); DeleteFile(temp_spare_path);
return success; return success;
} }
......
...@@ -606,7 +606,7 @@ ChildProcessResults DoLaunchChildTestProcess( ...@@ -606,7 +606,7 @@ ChildProcessResults DoLaunchChildTestProcess(
// On Windows, the reset() above is enough to delete the file since it was // On Windows, the reset() above is enough to delete the file since it was
// painted for such after being opened. Lesser platforms require an explicit // painted for such after being opened. Lesser platforms require an explicit
// delete now. // delete now.
if (!DeleteFile(output_filename, /*recursive=*/false)) if (!DeleteFile(output_filename))
LOG(WARNING) << "Failed to delete " << output_filename.AsUTF8Unsafe(); LOG(WARNING) << "Failed to delete " << output_filename.AsUTF8Unsafe();
#endif #endif
} }
......
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
// Unit tests for event trace consumer base class. // Unit tests for event trace consumer base class.
#include "base/win/event_trace_consumer.h"
#include <list> #include "base/win/event_trace_consumer.h"
#include <objbase.h> #include <objbase.h>
#include <list>
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
...@@ -276,7 +277,7 @@ class EtwTraceConsumerDataTest : public EtwTraceConsumerBaseTest { ...@@ -276,7 +277,7 @@ class EtwTraceConsumerDataTest : public EtwTraceConsumerBaseTest {
} }
void TearDown() override { void TearDown() override {
EXPECT_TRUE(DeleteFile(temp_file_, false)); EXPECT_TRUE(DeleteFile(temp_file_));
EtwTraceConsumerBaseTest::TearDown(); EtwTraceConsumerBaseTest::TearDown();
} }
...@@ -320,7 +321,7 @@ class EtwTraceConsumerDataTest : public EtwTraceConsumerBaseTest { ...@@ -320,7 +321,7 @@ class EtwTraceConsumerDataTest : public EtwTraceConsumerBaseTest {
} }
HRESULT RoundTripEvent(PEVENT_TRACE_HEADER header, PEVENT_TRACE* trace) { HRESULT RoundTripEvent(PEVENT_TRACE_HEADER header, PEVENT_TRACE* trace) {
DeleteFile(temp_file_, false); DeleteFile(temp_file_);
HRESULT hr = LogEventToTempSession(header); HRESULT hr = LogEventToTempSession(header);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
......
...@@ -165,7 +165,7 @@ TEST_F(EtwTraceControllerTest, StartFileSession) { ...@@ -165,7 +165,7 @@ TEST_F(EtwTraceControllerTest, StartFileSession) {
controller.StartFileSession(session_name_.c_str(), temp.value().c_str()); controller.StartFileSession(session_name_.c_str(), temp.value().c_str());
if (hr == E_ACCESSDENIED) { if (hr == E_ACCESSDENIED) {
VLOG(1) << "You must be an administrator to run this test on Vista"; VLOG(1) << "You must be an administrator to run this test on Vista";
DeleteFile(temp, false); DeleteFile(temp);
return; return;
} }
...@@ -175,7 +175,7 @@ TEST_F(EtwTraceControllerTest, StartFileSession) { ...@@ -175,7 +175,7 @@ TEST_F(EtwTraceControllerTest, StartFileSession) {
EXPECT_HRESULT_SUCCEEDED(controller.Stop(nullptr)); EXPECT_HRESULT_SUCCEEDED(controller.Stop(nullptr));
EXPECT_EQ(0u, controller.session()); EXPECT_EQ(0u, controller.session());
EXPECT_STREQ(L"", controller.session_name()); EXPECT_STREQ(L"", controller.session_name());
DeleteFile(temp, false); DeleteFile(temp);
} }
// This test is flaky for unclear reasons. See bugs 525297 and 534184 // This test is flaky for unclear reasons. See bugs 525297 and 534184
......
...@@ -112,7 +112,7 @@ void StoreImpl(const base::FilePath& cache_dir, ...@@ -112,7 +112,7 @@ void StoreImpl(const base::FilePath& cache_dir,
static_cast<int>(checksum.size())) { static_cast<int>(checksum.size())) {
LOG(ERROR) << "Failed to create ppd cache file"; LOG(ERROR) << "Failed to create ppd cache file";
file.Close(); file.Close();
if (!base::DeleteFile(path, false)) { if (!base::DeleteFile(path)) {
LOG(ERROR) << "Failed to cleanup failed creation."; LOG(ERROR) << "Failed to cleanup failed creation.";
} }
} else { } else {
......
...@@ -256,7 +256,7 @@ void SetTimezoneIDFromString(const std::string& id) { ...@@ -256,7 +256,7 @@ void SetTimezoneIDFromString(const std::string& id) {
} }
// Delete old symlink2 if it exists. // Delete old symlink2 if it exists.
base::DeleteFile(timezone_symlink2, false); base::DeleteFile(timezone_symlink2);
// Create new symlink2. // Create new symlink2.
if (symlink(timezone_file.value().c_str(), if (symlink(timezone_file.value().c_str(),
......
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