Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 1 | #include "bmc_dump_entry.hpp" |
| 2 | |
| 3 | #include "dump_manager.hpp" |
Dhruvaraj Subhashchandran | 580d91d | 2020-04-22 12:29:18 -0500 | [diff] [blame] | 4 | #include "dump_offload.hpp" |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 5 | #include "dump_utils.hpp" |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 6 | |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace dump |
| 12 | { |
| 13 | namespace bmc |
| 14 | { |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 15 | |
| 16 | void Entry::delete_() |
| 17 | { |
| 18 | // Delete Dump file from Permanent location |
| 19 | try |
| 20 | { |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 21 | std::filesystem::remove_all(file.parent_path()); |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 22 | } |
Patrick Williams | 9d2d722 | 2021-10-06 12:44:44 -0500 | [diff] [blame] | 23 | catch (const std::filesystem::filesystem_error& e) |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 24 | { |
| 25 | // Log Error message and continue |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 26 | lg2::error("Failed to delete dump file, errormsg: {ERROR}", "ERROR", e); |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | // Remove Dump entry D-bus object |
| 30 | phosphor::dump::Entry::delete_(); |
| 31 | } |
| 32 | |
Dhruvaraj Subhashchandran | 580d91d | 2020-04-22 12:29:18 -0500 | [diff] [blame] | 33 | void Entry::initiateOffload(std::string uri) |
| 34 | { |
| 35 | phosphor::dump::offload::requestOffload(file, id, uri); |
| 36 | offloaded(true); |
| 37 | } |
| 38 | |
Dhruvaraj Subhashchandran | 93f0641 | 2024-06-02 05:16:51 -0500 | [diff] [blame] | 39 | void Entry::updateFromFile(const std::filesystem::path& dumpPath) |
| 40 | { |
| 41 | // Extract dump details from the file name |
| 42 | auto dumpDetails = phosphor::dump::extractDumpDetails(dumpPath); |
| 43 | if (!dumpDetails) |
| 44 | { |
| 45 | lg2::error("Failed to extract dump details from file name: {PATH}", |
| 46 | "PATH", dumpPath); |
| 47 | throw std::logic_error("Invalid dump file name format"); |
| 48 | } |
| 49 | |
| 50 | auto [extractedId, extractedTimestamp, extractedSize] = *dumpDetails; |
| 51 | |
| 52 | if (id != extractedId) |
| 53 | { |
| 54 | lg2::error("Id({ID}) is not matching with id on filename" |
| 55 | "({ID_FILENAME})", |
| 56 | "ID", id, "ID_FILENAME", extractedId); |
| 57 | throw std::logic_error("Invalid dump id in filename"); |
| 58 | } |
| 59 | |
| 60 | // Update the entry with extracted details |
| 61 | startTime(extractedTimestamp); |
| 62 | elapsed(extractedTimestamp); |
| 63 | completedTime(extractedTimestamp); |
| 64 | size(extractedSize); |
| 65 | status(OperationStatus::Completed); |
| 66 | } |
| 67 | |
Dhruvaraj Subhashchandran | 4a98e8f | 2020-01-29 07:11:08 -0600 | [diff] [blame] | 68 | } // namespace bmc |
| 69 | } // namespace dump |
| 70 | } // namespace phosphor |