core: téléchargement avec reprise, archives tar et persistance
- Downloader : HEAD + Range avec reprise, re-probe à chaque essai (URL CDN signées), retries bornés, fichier partiel conservé, repli sans Range, annulation, progression et ETA - licence : fichier temporaire renommé à la fin ; le placeholder vide « licenses_<id>_<ts>.tar » renvoyé par Majestic pendant la génération de la licence est jeté et la requête relancée (cause du bug ENOENT de l'app officielle) - archives (libarchive) : vérification complète, extraction qui ignore UpdateInfo.xml, refus des chemins absolus/.., liens ignorés (FAT32) - persistance : vehicles.json compatible avec l'app officielle (BOM inclus), réglages + téléchargement en attente, chemins XDG / Haiku, écriture atomique - CLI : download, verify, extract ; Ctrl-C annule proprement - tests : faux CDN (coupures, sans Range, 4xx, annulation), tar ustar/gnu/pax/v7, corruption, traversal (42 cas, 322 assertions) - validé en réel : firmware RCC 8,39 Go téléchargé, interrompu, repris et vérifié (ustar, 16 entrées) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WDASLCiN764v685boRVYar
This commit is contained in:
1 parent
95704f9882
commit
543347a1e6
17 files changed
+2168
-40
No files matched your search
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "openpu/cancel.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
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<void(const ArchiveProgress&)>;
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user