OLD | NEW |
---|---|
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 OperationStatus LookUpCrashReport(const UUID& uuid, | 118 OperationStatus LookUpCrashReport(const UUID& uuid, |
119 Report* report) override; | 119 Report* report) override; |
120 OperationStatus GetPendingReports(std::vector<Report>* reports) override; | 120 OperationStatus GetPendingReports(std::vector<Report>* reports) override; |
121 OperationStatus GetCompletedReports(std::vector<Report>* reports) override; | 121 OperationStatus GetCompletedReports(std::vector<Report>* reports) override; |
122 OperationStatus GetReportForUploading(const UUID& uuid, | 122 OperationStatus GetReportForUploading(const UUID& uuid, |
123 const Report** report) override; | 123 const Report** report) override; |
124 OperationStatus RecordUploadAttempt(const Report* report, | 124 OperationStatus RecordUploadAttempt(const Report* report, |
125 bool successful, | 125 bool successful, |
126 const std::string& id) override; | 126 const std::string& id) override; |
127 OperationStatus SkipReportUpload(const UUID& uuid) override; | 127 OperationStatus SkipReportUpload(const UUID& uuid) override; |
128 OperationStatus DeleteReport(const UUID& uuid) override; | |
128 | 129 |
129 private: | 130 private: |
130 //! \brief A private extension of the Report class that maintains bookkeeping | 131 //! \brief A private extension of the Report class that maintains bookkeeping |
131 //! information of the database. | 132 //! information of the database. |
132 struct UploadReport : public Report { | 133 struct UploadReport : public Report { |
133 //! \brief Stores the flock of the file for the duration of | 134 //! \brief Stores the flock of the file for the duration of |
134 //! GetReportForUploading() and RecordUploadAttempt(). | 135 //! GetReportForUploading() and RecordUploadAttempt(). |
135 int lock_fd; | 136 int lock_fd; |
136 }; | 137 }; |
137 | 138 |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 base_dir_.Append(kCompletedDirectory).Append(report_path.BaseName()); | 470 base_dir_.Append(kCompletedDirectory).Append(report_path.BaseName()); |
470 if (rename(report_path.value().c_str(), new_path.value().c_str()) != 0) { | 471 if (rename(report_path.value().c_str(), new_path.value().c_str()) != 0) { |
471 PLOG(ERROR) << "rename " << report_path.value() << " to " | 472 PLOG(ERROR) << "rename " << report_path.value() << " to " |
472 << new_path.value(); | 473 << new_path.value(); |
473 return kFileSystemError; | 474 return kFileSystemError; |
474 } | 475 } |
475 | 476 |
476 return kNoError; | 477 return kNoError; |
477 } | 478 } |
478 | 479 |
480 CrashReportDatabase::OperationStatus CrashReportDatabaseMac::DeleteReport( | |
481 const UUID& uuid) { | |
482 INITIALIZATION_STATE_DCHECK_VALID(initialized_); | |
483 | |
484 base::FilePath report_path = LocateCrashReport(uuid); | |
485 if (report_path.empty()) | |
486 return kReportNotFound; | |
487 | |
488 base::ScopedFD lock(ObtainReportLock(report_path)); | |
489 if (!lock.is_valid()) | |
490 return kBusyError; | |
491 | |
492 lock.reset(); | |
Mark Mentovai
2015/10/07 03:54:27
What’s the thinking behind releasing the lock *bef
Robert Sesek
2015/10/07 16:24:34
I didn't expect to be able to unlink() with an flo
Mark Mentovai
2015/10/07 16:40:13
Robert Sesek wrote:
| |
493 if (unlink(report_path.value().c_str()) != 0) { | |
494 PLOG(ERROR) << "unlink " << report_path.value(); | |
495 return kFileSystemError; | |
496 } | |
497 | |
498 return kNoError; | |
499 } | |
500 | |
479 base::FilePath CrashReportDatabaseMac::LocateCrashReport(const UUID& uuid) { | 501 base::FilePath CrashReportDatabaseMac::LocateCrashReport(const UUID& uuid) { |
480 const std::string target_uuid = uuid.ToString(); | 502 const std::string target_uuid = uuid.ToString(); |
481 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) { | 503 for (size_t i = 0; i < arraysize(kReportDirectories); ++i) { |
482 base::FilePath path = | 504 base::FilePath path = |
483 base_dir_.Append(kReportDirectories[i]) | 505 base_dir_.Append(kReportDirectories[i]) |
484 .Append(target_uuid + "." + kCrashReportFileExtension); | 506 .Append(target_uuid + "." + kCrashReportFileExtension); |
485 | 507 |
486 // Test if the path exists. | 508 // Test if the path exists. |
487 struct stat st; | 509 struct stat st; |
488 if (lstat(path.value().c_str(), &st)) { | 510 if (lstat(path.value().c_str(), &st)) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 const base::FilePath& path) { | 624 const base::FilePath& path) { |
603 scoped_ptr<CrashReportDatabaseMac> database_mac( | 625 scoped_ptr<CrashReportDatabaseMac> database_mac( |
604 new CrashReportDatabaseMac(path)); | 626 new CrashReportDatabaseMac(path)); |
605 if (!database_mac->Initialize()) | 627 if (!database_mac->Initialize()) |
606 database_mac.reset(); | 628 database_mac.reset(); |
607 | 629 |
608 return scoped_ptr<CrashReportDatabase>(database_mac.release()); | 630 return scoped_ptr<CrashReportDatabase>(database_mac.release()); |
609 } | 631 } |
610 | 632 |
611 } // namespace crashpad | 633 } // namespace crashpad |
OLD | NEW |