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

Unified Diff: client/crash_report_database_win.cc

Issue 1395653002: crashpad_database_util: Don’t create a database unless explicitly asked (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: client/crash_report_database_win.cc
diff --git a/client/crash_report_database_win.cc b/client/crash_report_database_win.cc
index f270530b70fdd54fedba79a1708924aa244291ea..d9c48d3e08eb2338b2098c82a2d20c9243ac1576 100644
--- a/client/crash_report_database_win.cc
+++ b/client/crash_report_database_win.cc
@@ -483,6 +483,20 @@ OperationStatus Metadata::VerifyReport(const ReportDisk& report_disk,
: CrashReportDatabase::kBusyError;
}
+bool EnsureDirectory(const base::FilePath& path) {
+ DWORD fileattr = GetFileAttributes(path.value().c_str());
+ if (fileattr == INVALID_FILE_ATTRIBUTES) {
+ PLOG(ERROR) << "GetFileAttributes " << base::UTF16ToUTF8(path.value());
+ return false;
+ }
+ if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0)
+ return true;
+ LOG(ERROR) << "GetFileAttributes "
+ << base::UTF16ToUTF8(path.value())
+ << ": not a directory";
+ return false;
+}
+
//! \brief Ensures that the node at path is a directory, and creates it if it
//! does not exist.
//!
@@ -493,18 +507,10 @@ bool CreateDirectoryIfNecessary(const base::FilePath& path) {
if (CreateDirectory(path.value().c_str(), nullptr))
return true;
if (GetLastError() != ERROR_ALREADY_EXISTS) {
- PLOG(ERROR) << "CreateDirectory";
+ PLOG(ERROR) << "CreateDirectory " << base::UTF16ToUTF8(path.value());
return false;
}
- DWORD fileattr = GetFileAttributes(path.value().c_str());
- if (fileattr == INVALID_FILE_ATTRIBUTES) {
- PLOG(ERROR) << "GetFileAttributes";
- return false;
- }
- if ((fileattr & FILE_ATTRIBUTE_DIRECTORY) != 0)
- return true;
- LOG(ERROR) << "not a directory";
- return false;
+ return EnsureDirectory(path);
}
// CrashReportDatabaseWin ------------------------------------------------------
@@ -514,7 +520,7 @@ class CrashReportDatabaseWin : public CrashReportDatabase {
explicit CrashReportDatabaseWin(const base::FilePath& path);
~CrashReportDatabaseWin() override;
- bool Initialize();
+ bool Initialize(bool create);
// CrashReportDatabase:
Settings* GetSettings() override;
@@ -552,12 +558,19 @@ CrashReportDatabaseWin::CrashReportDatabaseWin(const base::FilePath& path)
CrashReportDatabaseWin::~CrashReportDatabaseWin() {
}
-bool CrashReportDatabaseWin::Initialize() {
+bool CrashReportDatabaseWin::Initialize(bool create) {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
- // Ensure the database and report subdirectories exist.
- if (!CreateDirectoryIfNecessary(base_dir_) ||
- !CreateDirectoryIfNecessary(base_dir_.Append(kReportsDirectory)))
+ // Ensure the databse directory exists.
+ if (create) {
+ if (!CreateDirectoryIfNecessary(base_dir_))
+ return false;
+ } else if (!EnsureDirectory(base_dir_)) {
+ return false;
+ }
+
+ // Ensure that the report subdirectory exists.
+ if (!CreateDirectoryIfNecessary(base_dir_.Append(kReportsDirectory)))
return false;
// TODO(scottmg): When are completed reports pruned from disk? Delete here or
@@ -755,11 +768,11 @@ scoped_ptr<Metadata> CrashReportDatabaseWin::AcquireMetadata() {
// static
scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize(
- const base::FilePath& path) {
+ const base::FilePath& path, bool create) {
scoped_ptr<CrashReportDatabaseWin> database_win(
new CrashReportDatabaseWin(path));
- return database_win->Initialize() ? database_win.Pass()
- : scoped_ptr<CrashReportDatabaseWin>();
+ return database_win->Initialize(create)
+ ? database_win.Pass() : scoped_ptr<CrashReportDatabaseWin>();
}
} // namespace crashpad

Powered by Google App Engine
This is Rietveld 408576698