blob: 05d1f10adaa5712fd9239efc5691956d7dcb4a73 [file] [log] [blame]
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -06001#include "bmc_dump_entry.hpp"
2
3#include "dump_manager.hpp"
Dhruvaraj Subhashchandran580d91d2020-04-22 12:29:18 -05004#include "dump_offload.hpp"
Dhruvaraj Subhashchandran93f06412024-06-02 05:16:51 -05005#include "dump_utils.hpp"
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -06006
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05007#include <phosphor-logging/lg2.hpp>
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -06008
9namespace phosphor
10{
11namespace dump
12{
13namespace bmc
14{
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060015
16void Entry::delete_()
17{
18 // Delete Dump file from Permanent location
19 try
20 {
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050021 std::filesystem::remove_all(file.parent_path());
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060022 }
Patrick Williams9d2d7222021-10-06 12:44:44 -050023 catch (const std::filesystem::filesystem_error& e)
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060024 {
25 // Log Error message and continue
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050026 lg2::error("Failed to delete dump file, errormsg: {ERROR}", "ERROR", e);
Dhruvaraj Subhashchandran4a98e8f2020-01-29 07:11:08 -060027 }
28
29 // Remove Dump entry D-bus object
30 phosphor::dump::Entry::delete_();
31}
32
Dhruvaraj Subhashchandran580d91d2020-04-22 12:29:18 -050033void Entry::initiateOffload(std::string uri)
34{
35 phosphor::dump::offload::requestOffload(file, id, uri);
36 offloaded(true);
37}
38
Dhruvaraj Subhashchandran93f06412024-06-02 05:16:51 -050039void 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 Subhashchandran4a98e8f2020-01-29 07:11:08 -060068} // namespace bmc
69} // namespace dump
70} // namespace phosphor