blob: 5cfbd545ded7532c355d562b3ffdf049172fd331 [file] [log] [blame]
Jagpal Singh Gill2431e7f2024-04-07 23:51:12 -07001#pragma once
2
3#include <boost/asio/io_context.hpp>
4
5#include <filesystem>
6
7namespace phosphor::software::utils
8{
9
10namespace fs = std::filesystem;
11
12struct RemovablePath
13{
14 fs::path path;
15
16 explicit RemovablePath(const fs::path& path) : path(path) {}
17 ~RemovablePath()
18 {
19 if (!path.empty())
20 {
21 std::error_code ec;
22 fs::remove_all(path, ec);
23 }
24 }
25
26 RemovablePath(const RemovablePath& other) = delete;
27 RemovablePath& operator=(const RemovablePath& other) = delete;
28 RemovablePath(RemovablePath&&) = delete;
29 RemovablePath& operator=(RemovablePath&&) = delete;
30};
31
32/** @brief Untar the image
33 * @param[in] imageFd - The file descriptor of the image to untar.
34 * @param[in] extractDirPath - The destination directory for the untarred
35 * image.
36 * @param[out] bool - The result of the untar operation.
37 */
38bool unTar(int imageFd, const std::string& extractDirPath);
39
40} // namespace phosphor::software::utils
41
42boost::asio::io_context& getIOContext();