Chromium Code Reviews| 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..6ebc16df79208c8185cbc2dfaf7e97b3f2ced728 100644 |
| --- a/client/crash_report_database_win.cc |
| +++ b/client/crash_report_database_win.cc |
| @@ -483,6 +483,21 @@ 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) { |
| + LOG(ERROR) << "GetFileAttributes " |
| + << base::UTF16ToUTF8(path.value()) |
| + << ": not a directory"; |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| //! \brief Ensures that the node at path is a directory, and creates it if it |
| //! does not exist. |
| //! |
| @@ -493,18 +508,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 +521,7 @@ class CrashReportDatabaseWin : public CrashReportDatabase { |
| explicit CrashReportDatabaseWin(const base::FilePath& path); |
| ~CrashReportDatabaseWin() override; |
| - bool Initialize(); |
| + bool Initialize(bool may_create); |
| // CrashReportDatabase: |
| Settings* GetSettings() override; |
| @@ -552,12 +559,19 @@ CrashReportDatabaseWin::CrashReportDatabaseWin(const base::FilePath& path) |
| CrashReportDatabaseWin::~CrashReportDatabaseWin() { |
| } |
| -bool CrashReportDatabaseWin::Initialize() { |
| +bool CrashReportDatabaseWin::Initialize(bool may_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. |
|
scottmg
2015/10/07 20:58:18
'database' if you didn't already land.
Mark Mentovai
2015/10/07 21:03:34
scottmg wrote:
|
| + if (may_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 |
| @@ -751,15 +765,26 @@ scoped_ptr<Metadata> CrashReportDatabaseWin::AcquireMetadata() { |
| return Metadata::Create(metadata_file, base_dir_.Append(kReportsDirectory)); |
| } |
| +scoped_ptr<CrashReportDatabase> InitializeInternal( |
| + const base::FilePath& path, bool may_create) { |
| + scoped_ptr<CrashReportDatabaseWin> database_win( |
| + new CrashReportDatabaseWin(path)); |
| + return database_win->Initialize(may_create) |
| + ? database_win.Pass() : scoped_ptr<CrashReportDatabaseWin>(); |
|
Robert Sesek
2015/10/07 21:04:33
nit: shouldn't ? go on the previous line?
Mark Mentovai
2015/10/07 21:07:09
Robert Sesek wrote:
|
| +} |
| + |
| } // namespace |
| // static |
| scoped_ptr<CrashReportDatabase> CrashReportDatabase::Initialize( |
| const base::FilePath& path) { |
| - scoped_ptr<CrashReportDatabaseWin> database_win( |
| - new CrashReportDatabaseWin(path)); |
| - return database_win->Initialize() ? database_win.Pass() |
| - : scoped_ptr<CrashReportDatabaseWin>(); |
| + return InitializeInternal(path, true); |
| +} |
| + |
| +// static |
| +scoped_ptr<CrashReportDatabase> CrashReportDatabase::InitializeWithoutCreating( |
| + const base::FilePath& path) { |
| + return InitializeInternal(path, false); |
| } |
| } // namespace crashpad |