Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: base/files/scoped_temp_dir.cc

Issue 2854323002: Make TestingProfile delete failures explicitly CHECK-fail.
Patch Set: TEMP: Deliberately crash tests on ~ScopedTempDir, to see logs. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/files/scoped_temp_dir.h ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/files/scoped_temp_dir.h" 5 #include "base/files/scoped_temp_dir.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace base { 10 namespace base {
11 11
12 ScopedTempDir::ScopedTempDir() { 12 ScopedTempDir::ScopedTempDir() {
13 } 13 }
14 14
15 ScopedTempDir::~ScopedTempDir() { 15 ScopedTempDir::~ScopedTempDir() {
16 if (!path_.empty() && !Delete()) 16 if (!path_.empty()) {
17 DLOG(WARNING) << "Could not delete temp dir in dtor."; 17 if (!Delete())
18 DLOG(WARNING) << "Could not delete temp dir in dtor.";
19 else
20 LOG(WARNING) << "Delete in ~ScopedTempDir succeeded";
21 } else {
22 LOG(WARNING) << "Not calling Delete in ~ScopedTempDir (path empty)";
23 }
24
25 CHECK(false) << "Deliberate crash.";
18 } 26 }
19 27
20 bool ScopedTempDir::CreateUniqueTempDir() { 28 bool ScopedTempDir::CreateUniqueTempDir() {
21 if (!path_.empty()) 29 if (!path_.empty())
22 return false; 30 return false;
23 31
24 // This "scoped_dir" prefix is only used on Windows and serves as a template 32 // This "scoped_dir" prefix is only used on Windows and serves as a template
25 // for the unique name. 33 // for the unique name.
26 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), &path_)) 34 if (!base::CreateNewTempDirectory(FILE_PATH_LITERAL("scoped_dir"), &path_))
27 return false; 35 return false;
(...skipping 23 matching lines...) Expand all
51 return false; 59 return false;
52 60
53 if (!DirectoryExists(path) && !base::CreateDirectory(path)) 61 if (!DirectoryExists(path) && !base::CreateDirectory(path))
54 return false; 62 return false;
55 63
56 path_ = path; 64 path_ = path;
57 return true; 65 return true;
58 } 66 }
59 67
60 bool ScopedTempDir::Delete() { 68 bool ScopedTempDir::Delete() {
61 if (path_.empty()) 69 if (path_.empty()) {
70 LOG(WARNING) << "ScopedTempDir::Delete: Failing due to path being empty";
62 return false; 71 return false;
72 }
63 73
64 bool ret = base::DeleteFile(path_, true); 74 bool ret = base::DeleteFile(path_, true);
65 if (ret) { 75 if (ret) {
66 // We only clear the path if deleted the directory. 76 // We only clear the path if deleted the directory.
77 LOG(WARNING)
78 << "ScopedTempDir::Delete: DeleteFile Succeeded; clearing path";
67 path_.clear(); 79 path_.clear();
80 } else {
81 LOG(WARNING) << "ScopedTempDir::Delete: DeleteFile Failed";
68 } 82 }
69 83
70 return ret; 84 return ret;
71 } 85 }
72 86
73 FilePath ScopedTempDir::Take() { 87 FilePath ScopedTempDir::Take() {
74 FilePath ret = path_; 88 FilePath ret = path_;
75 path_ = FilePath(); 89 path_ = FilePath();
76 return ret; 90 return ret;
77 } 91 }
78 92
79 const FilePath& ScopedTempDir::GetPath() const { 93 const FilePath& ScopedTempDir::GetPath() const {
80 DCHECK(!path_.empty()) << "Did you call CreateUniqueTempDir* before?"; 94 DCHECK(!path_.empty()) << "Did you call CreateUniqueTempDir* before?";
81 return path_; 95 return path_;
82 } 96 }
83 97
98 bool ScopedTempDir::IsEmpty() const {
99 return path_.empty();
100 }
101
84 bool ScopedTempDir::IsValid() const { 102 bool ScopedTempDir::IsValid() const {
85 return !path_.empty() && DirectoryExists(path_); 103 return !IsEmpty() && DirectoryExists(path_);
86 } 104 }
87 105
88 } // namespace base 106 } // namespace base
OLDNEW
« no previous file with comments | « base/files/scoped_temp_dir.h ('k') | chrome/test/base/testing_profile.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698