- 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
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <filesystem>
|
|
#include <fstream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
/// Self-deleting temporary directory.
|
|
class TempDir {
|
|
public:
|
|
TempDir()
|
|
{
|
|
static std::atomic<int> counter{0};
|
|
path_ = std::filesystem::temp_directory_path() /
|
|
("openpu-test-" + std::to_string(std::chrono::steady_clock::now().time_since_epoch().count()) + "-" +
|
|
std::to_string(counter++));
|
|
std::filesystem::create_directories(path_);
|
|
}
|
|
TempDir(const TempDir&) = delete;
|
|
TempDir& operator=(const TempDir&) = delete;
|
|
~TempDir()
|
|
{
|
|
std::error_code ec;
|
|
std::filesystem::remove_all(path_, ec);
|
|
}
|
|
const std::filesystem::path& path() const { return path_; }
|
|
|
|
private:
|
|
std::filesystem::path path_;
|
|
};
|
|
|
|
inline std::string readAll(const std::filesystem::path& p)
|
|
{
|
|
std::ifstream in(p, std::ios::binary);
|
|
std::stringstream ss;
|
|
ss << in.rdbuf();
|
|
return ss.str();
|
|
}
|
|
|
|
inline void writeAll(const std::filesystem::path& p, const std::string& content)
|
|
{
|
|
std::filesystem::create_directories(p.parent_path());
|
|
std::ofstream out(p, std::ios::binary | std::ios::trunc);
|
|
out << content;
|
|
}
|