1 #include "bmc_dump_entry.hpp"
2 
3 #include "dump_manager.hpp"
4 #include "dump_offload.hpp"
5 #include "dump_utils.hpp"
6 
7 #include <phosphor-logging/lg2.hpp>
8 
9 namespace phosphor
10 {
11 namespace dump
12 {
13 namespace bmc
14 {
15 
delete_()16 void Entry::delete_()
17 {
18     // Delete Dump file from Permanent location
19     try
20     {
21         std::filesystem::remove_all(file.parent_path());
22     }
23     catch (const std::filesystem::filesystem_error& e)
24     {
25         // Log Error message and continue
26         lg2::error("Failed to delete dump file, errormsg: {ERROR}", "ERROR", e);
27     }
28 
29     // Remove Dump entry D-bus object
30     phosphor::dump::Entry::delete_();
31 }
32 
initiateOffload(std::string uri)33 void Entry::initiateOffload(std::string uri)
34 {
35     phosphor::dump::offload::requestOffload(file, id, uri);
36     offloaded(true);
37 }
38 
updateFromFile(const std::filesystem::path & dumpPath)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 
68 } // namespace bmc
69 } // namespace dump
70 } // namespace phosphor
71