// SPDX-License-Identifier: MIT #pragma once #include "openpu/cancel.hpp" #include #include #include #include #include namespace openpu { struct ArchiveProgress { std::uint64_t processed = 0; ///< bytes of the archive consumed so far std::uint64_t total = 0; ///< archive size std::uint64_t entries = 0; ///< entries seen so far std::string current; ///< entry being processed }; using ArchiveProgressCallback = std::function; class ArchiveError : public std::runtime_error { public: enum class Kind { Corrupt, ///< the archive is damaged or not a tar: delete it and download again Io, ///< cannot read the archive or write the destination (full / removed drive...) }; ArchiveError(Kind kind, const std::string& what) : std::runtime_error(what), kind_(kind) {} Kind kind() const noexcept { return kind_; } private: Kind kind_; }; /// Reads every entry of a tar archive, without writing anything, to check its integrity. void verifyTar(const std::filesystem::path& archive, const ArchiveProgressCallback& onProgress = {}, const CancelToken* cancel = nullptr); /// Extracts a tar archive below `destination` (typically the USB stick root). /// Entries named UpdateInfo.xml (any directory) are skipped, as in the official application. /// Absolute paths, `..` components and links escaping the destination are refused; owners and /// permissions are not restored (the target is FAT32). void extractTar(const std::filesystem::path& archive, const std::filesystem::path& destination, const ArchiveProgressCallback& onProgress = {}, const CancelToken* cancel = nullptr); /// Sum of the uncompressed sizes of the regular files of an archive that extractTar would write. std::uint64_t tarPayloadSize(const std::filesystem::path& archive); } // namespace openpu