Play your Steam library's Windows games on a jailbroken PS5.
C++
Download several Steam chunks at once
Leonardo Lobato0e178084c3f0
diff --git a/src/homebrew/ps5.cpp b/src/homebrew/ps5.cppindex 102b0cf..717a3a5 100644--- a/src/homebrew/ps5.cpp+++ b/src/homebrew/ps5.cpp@@ -272,6 +272,9 @@ int main() {install_cm.SetSharedSession(steam_cm);playden::steam::CdnClient install_cdn(paths.trust_store);playden::steam::SteamInstallRunner install_runner(install_cm, install_cdn);+ install_runner.SetTuning([root = paths.title_root] {+ return playden::steam::ReadDownloadTuning(root + "/dev/download-tuning.txt");+ });install_runner.SetLog([](playden::GameId app, const char* step, const char* category, const char* detail) {char line[640];if (std::string(step) == "install-removal")diff --git a/src/steam/backend/cdn_client.h b/src/steam/backend/cdn_client.hindex 306204e..6f01950 100644--- a/src/steam/backend/cdn_client.h+++ b/src/steam/backend/cdn_client.h@@ -48,6 +48,7 @@ class CdnClient {// The last failure as "http=<status>" or "transport=<category>", for sanitized logs.const CdnStats& stats() const { return stats_; }const std::string& last_failure() const { return last_failure_; }+ const std::string& ca_bundle() const { return ca_bundle_; }private:CdnError Get(const std::string& url, std::size_t max_bytes, std::uint32_t timeout_ms,diff --git a/src/steam/backend/depot_installer.cpp b/src/steam/backend/depot_installer.cppindex da70fe7..e46ef71 100644--- a/src/steam/backend/depot_installer.cpp+++ b/src/steam/backend/depot_installer.cpp@@ -16,6 +16,10 @@#include <cstdio>#include <cstring>#include <limits>+#include <condition_variable>+#include <mutex>+#include <pthread.h>+#include <charconv>#include <map>#include <memory>#include <set>@@ -184,6 +188,35 @@ std::string JournalKey(std::uint32_t depot, const std::string& path, std::uint64} // namespace+DownloadTuning ReadDownloadTuning(const std::string& path) {+ DownloadTuning tuning;+ FILE* input = std::fopen(path.c_str(), "r");+ if (!input) return tuning;+ ScopeExit close{[&] { std::fclose(input); }};+ char line[128];+ bool seen_slots = false, seen_ahead = false;+ while (std::fgets(line, sizeof(line), input)) {+ std::string text(line);+ while (!text.empty() && (text.back() == '\n' || text.back() == '\r')) text.pop_back();+ if (text.empty()) continue;+ const auto equals = text.find('=');+ if (equals == std::string::npos) return {};+ int value = 0;+ const auto parsed = std::from_chars(text.data() + equals + 1, text.data() + text.size(), value);+ if (parsed.ec != std::errc{} || parsed.ptr != text.data() + text.size()) return {};+ const auto key = text.substr(0, equals);+ if (key == "slots" && !seen_slots) {+ seen_slots = true;+ tuning.slots = std::clamp(value, 1, 8);+ } else if (key == "ahead" && !seen_ahead && value >= 1 && value <= 65536) {+ seen_ahead = true;+ tuning.ahead_files = value;+ } else return {};+ }+ if (std::ferror(input)) return {};+ return tuning;+}+const char* InstallErrorName(InstallError error) {switch (error) {case InstallError::kNone: return "none";@@ -232,9 +265,17 @@ DepotInstaller::DepotInstaller(CmClient& cm, CdnClient& cdn) {if (!ValidateDepotManifest(*out, &reason)) return corrupt("invalid " + reason);return InstallError::kNone;};- hooks_.chunk = [&cdn](const ContentServer& server, std::uint32_t depot, const std::string& sha,- std::size_t max_bytes, const std::atomic<bool>& cancel, std::vector<std::uint8_t>* out) {- return cdn.Chunk(server, depot, sha, max_bytes, cancel, out);+ const auto ca_bundle = cdn.ca_bundle();+ hooks_.make_fetcher = [ca_bundle] {+ auto client = std::make_shared<CdnClient>(ca_bundle);+ InstallerHooks::ChunkFetcher fetcher;+ fetcher.fetch = [client](const ContentServer& server, std::uint32_t depot, const std::string& sha,+ std::size_t cap, const std::atomic<bool>& cancel, std::vector<std::uint8_t>* out) {+ return client->Chunk(server, depot, sha, cap, cancel, out);+ };+ fetcher.last_failure = [client] { return client->last_failure(); };+ fetcher.stats = [client] { return client->stats(); };+ return fetcher;};hooks_.cdn_stats = [&cdn] { return cdn.stats(); };hooks_.free_bytes = &DefaultFreeBytes;@@ -255,6 +296,12 @@ InstallOutcome DepotInstaller::Run(const StoredSession& session, const InstallTaconst std::function<void(const InstallProgress&)>& on_progress) {InstallOutcome outcome;InstallStats stats;+ const int slots = std::clamp(tuning_.slots, 1, 8);+ const int ahead_files = std::clamp(tuning_.ahead_files, 1, 65536);+ stats.slots = slots; stats.ahead_files = ahead_files;+ CdnStats worker_cdn;+ bool workers_running = false;+ CdnStats coordinator_cdn;const auto initial_cdn = hooks_.cdn_stats ? hooks_.cdn_stats() : CdnStats{};Clock::duration fetch{}, process{}, create{}, write{}, journal_time{}, backoff{};auto phase_start = Clock::now();@@ -267,12 +314,16 @@ InstallOutcome DepotInstaller::Run(const StoredSession& session, const InstallTastats.journal_ms = Milliseconds(journal_time); stats.backoff_ms = Milliseconds(backoff);if (download_start != Clock::time_point{} && !loop_finished)stats.download_ms = Milliseconds(Clock::now() - download_start);- if (hooks_.cdn_stats) {- const auto current = hooks_.cdn_stats();+ {+ const auto current = workers_running ? coordinator_cdn : (hooks_.cdn_stats ? hooks_.cdn_stats() : CdnStats{});#define CDN_DELTA(field) stats.field = current.field - initial_cdn.fieldCDN_DELTA(requests); CDN_DELTA(failures); CDN_DELTA(resolve_ms); CDN_DELTA(connect_ms);CDN_DELTA(tls_ms); CDN_DELTA(first_byte_ms); CDN_DELTA(total_ms); CDN_DELTA(new_connections); CDN_DELTA(bytes);#undef CDN_DELTA+#define CDN_ADD(field) stats.field += worker_cdn.field+ CDN_ADD(requests); CDN_ADD(failures); CDN_ADD(resolve_ms); CDN_ADD(connect_ms);+ CDN_ADD(tls_ms); CDN_ADD(first_byte_ms); CDN_ADD(total_ms); CDN_ADD(new_connections); CDN_ADD(bytes);+#undef CDN_ADD}hooks_.stats(phase, stats);};@@ -426,83 +477,262 @@ InstallOutcome DepotInstaller::Run(const StoredSession& session, const InstallTaconst auto now = Clock::now();if (now - last_stats >= std::chrono::seconds(60)) { emit("progress"); last_stats = now; }};- std::size_t server_cursor = 0;+ struct FileWork {+ Placement placement;+ bool prepared = false;+ std::size_t pending = 0;+ };+ struct ChunkWork { std::size_t file; const ManifestChunk* chunk; std::string journal_key; };+ std::vector<FileWork> files;+ std::vector<ChunkWork> chunks;for (const auto& [key, placement] : placements) {- report_progress();- const auto& file = *placement.file;- const std::string path = target.install_root + "/" + file.path;- if (file.is_directory()) {- if (!Timed(create, [&] { return MakeDirs(path, &stats.folders_created); })) { std::fclose(journal); return fail(InstallError::kStorage, "cannot create folder"); }- continue;+ if (placement.file->is_symlink()) continue;+ const auto index = files.size();+ files.push_back({placement, false, 0});+ for (const auto& chunk : placement.file->chunks) {+ auto entry = JournalKey(access.grants[placement.depot].depot_id, placement.file->path, chunk.offset);+ if (done.count(entry)) continue;+ chunks.push_back({index, &chunk, std::move(entry)});+ ++files.back().pending;}- if (file.is_symlink()) continue; // recorded in the install record; the console has no symlinks- if (!Timed(create, [&] { return MakeDirs(Parent(path), &stats.folders_created); })) { std::fclose(journal); return fail(InstallError::kStorage, "cannot create folder"); }- const bool existed = Exists(path);- if (file.chunks.empty() || !existed) {- if (!Timed(create, [&] { return EnsureFileSize(path, file.size); })) { std::fclose(journal); return fail(InstallError::kStorage, "cannot create file"); }- if (!existed) ++stats.files_created;+ }+ struct Worker {+ InstallerHooks::ChunkFetcher fetcher;+ pthread_t thread{};+ bool started = false, busy = false, ready = false;+ std::size_t work = 0;+ std::vector<std::uint8_t> plain;+ std::uint64_t compressed_bytes = 0, retries = 0, corrupt_retries = 0;+ Clock::duration fetch{}, process{}, backoff{};+ CdnStats cdn;+ std::function<void()> run;+ };+ std::vector<std::unique_ptr<Worker>> workers;+ std::mutex mutex;+ std::condition_variable changed;+ std::atomic<bool> stop{false};+ std::size_t next_chunk = 0, occupied = 0, waiting = 0;+ std::uint32_t peak_active = 0, peak_waiting = 0;+ InstallError first_error = InstallError::kNone;+ std::string first_detail;+ const auto fail_locked = [&](InstallError error, std::string detail) {+ if (first_error == InstallError::kNone) {+ first_error = error;+ first_detail = std::move(detail);}- const auto& grant = access.grants[placement.depot];- for (const auto& chunk : file.chunks) {- report_progress();- const auto entry = JournalKey(grant.depot_id, file.path, chunk.offset);- if (done.count(entry)) continue;- if (cancel.load()) { std::fclose(journal); return fail(InstallError::kCanceled, "canceled"); }- if (progress.download_done == 0) trace("first-chunk");- std::vector<std::uint8_t> plain;- std::uint64_t compressed_bytes = 0;- InstallError result = InstallError::kNetwork;- const auto attempts = static_cast<std::size_t>(kChunkAttempts) * std::max<std::size_t>(1, std::min<std::size_t>(servers.size(), 2));- for (std::size_t attempt = 0; attempt < attempts; ++attempt) {- if (attempt > 0) ++stats.chunk_retries;- std::vector<std::uint8_t> encrypted;- const auto fetched = Timed(fetch, [&] {- return hooks_.chunk(servers[server_cursor % servers.size()], grant.depot_id, Hex(chunk.sha),- static_cast<std::size_t>(chunk.compressed_size) + 4096, cancel, &encrypted);- });- report_progress();- if (fetched == CdnError::kCanceled) { std::fclose(journal); return fail(InstallError::kCanceled, "canceled"); }- if (fetched != CdnError::kNone) {- ++server_cursor;- result = InstallError::kNetwork;- // 1, 2, 4, 8 s before the next try, so a short CDN outage does not end the download.- if (hooks_.pause && attempt + 1 < attempts)- Timed(backoff, [&] { hooks_.pause(1000 << std::min<std::size_t>(attempt, 3), cancel); });- continue;- }- const auto processed = Timed(process, [&] {- return ProcessDepotChunk(encrypted, grant.key, chunk.original_size, chunk.crc, chunk.sha, &plain);- });- if (processed == ChunkError::kNone) {- compressed_bytes = encrypted.size();- result = InstallError::kNone;- break;+ stop.store(true);+ changed.notify_all();+ };+ const auto publish_failure = [&](InstallError error, std::string detail) {+ std::lock_guard<std::mutex> lock(mutex);+ fail_locked(error, std::move(detail));+ };+ // Workers publish their own counters under this lock. Never query their clients here.+ const auto snapshot = [&] {+ std::lock_guard<std::mutex> lock(mutex);+ fetch = {}; process = {}; backoff = {}; worker_cdn = {};+ stats.peak_active = peak_active; stats.peak_waiting = peak_waiting;+ stats.chunk_retries = stats.corrupt_retries = 0;+ for (const auto& worker : workers) {+ fetch += worker->fetch; process += worker->process; backoff += worker->backoff;+ stats.chunk_retries += worker->retries; stats.corrupt_retries += worker->corrupt_retries;+#define SUM_CDN(field) worker_cdn.field += worker->cdn.field+ SUM_CDN(requests); SUM_CDN(failures); SUM_CDN(resolve_ms); SUM_CDN(connect_ms); SUM_CDN(tls_ms);+ SUM_CDN(first_byte_ms); SUM_CDN(total_ms); SUM_CDN(new_connections); SUM_CDN(bytes);+#undef SUM_CDN+ }+ };+ const auto join_workers = [&] {+ stop.store(true);+ changed.notify_all();+ for (auto& worker : workers) {+ if (worker->started) { pthread_join(worker->thread, nullptr); worker->started = false; }+ }+ workers_running = false;+ snapshot();+ };+ ScopeExit joined{join_workers};+ ScopeExit close_journal{[&] { if (journal) std::fclose(journal); }};+ coordinator_cdn = hooks_.cdn_stats ? hooks_.cdn_stats() : CdnStats{};+ workers_running = true;+ if (!chunks.empty()) trace("first-chunk");+ pthread_attr_t attr;+ const bool attr_ready = pthread_attr_init(&attr) == 0;+ const bool stack_ready = attr_ready && pthread_attr_setstacksize(&attr, 256 * 1024) == 0;+ if (!stack_ready && !chunks.empty()) publish_failure(InstallError::kNetwork, "cannot start workers");+ for (int index = 0; stack_ready && index < slots && !chunks.empty() && !stop.load(); ++index) {+ auto worker = std::make_unique<Worker>();+#if defined(__cpp_exceptions)+ try {+#endif+ if (hooks_.make_fetcher) worker->fetcher = hooks_.make_fetcher();+ else { worker->fetcher.fetch = hooks_.chunk; worker->fetcher.last_failure = hooks_.last_failure; }+#if defined(__cpp_exceptions)+ } catch (...) { publish_failure(InstallError::kNetwork, "cannot create fetcher"); break; }+#endif+ if (!worker->fetcher.fetch) { publish_failure(InstallError::kNetwork, "cannot create fetcher"); break; }+ auto* self = worker.get();+ self->run = [&, self] {+ // Destroy the HTTP client on the same thread that used it, after publishing its counters.+ ScopeExit release_fetcher{[self] { self->fetcher = {}; }};+ std::size_t server_cursor = 0;+ Clock::duration fetch_time{}, process_time{}, backoff_time{};+ std::uint64_t retries = 0, corrupt_retries = 0;+#if defined(__cpp_exceptions)+ try {+#endif+ while (!stop.load()) {+ {+ std::unique_lock<std::mutex> lock(mutex);+ changed.wait(lock, [&] { return stop.load() || !self->busy; });+ if (stop.load() || next_chunk == chunks.size()) break;+ self->work = next_chunk++;+ self->busy = true;+ ++occupied;+ peak_active = std::max(peak_active, static_cast<std::uint32_t>(occupied));+ }+ const auto& work = chunks[self->work];+ const auto& placement = files[work.file].placement;+ const auto& grant = access.grants[placement.depot];+ const auto& chunk = *work.chunk;+ InstallError result = InstallError::kNetwork;+ std::string detail;+ std::vector<std::uint8_t> plain;+ std::uint64_t compressed_bytes = 0;+ const auto attempts = static_cast<std::size_t>(kChunkAttempts) * std::min<std::size_t>(servers.size(), 2);+ for (std::size_t attempt = 0; attempt < attempts && !stop.load(); ++attempt) {+ if (attempt > 0) ++retries;+ std::vector<std::uint8_t> encrypted;+ const auto fetched = Timed(fetch_time, [&] {+ return self->fetcher.fetch(servers[server_cursor % servers.size()], grant.depot_id, Hex(chunk.sha),+ static_cast<std::size_t>(chunk.compressed_size) + 4096, stop, &encrypted);+ });+ if (fetched == CdnError::kCanceled || stop.load()) { result = InstallError::kCanceled; break; }+ if (fetched != CdnError::kNone) {+ ++server_cursor;+ result = InstallError::kNetwork;+ if (hooks_.pause && attempt + 1 < attempts)+ Timed(backoff_time, [&] { hooks_.pause(1000 << std::min<std::size_t>(attempt, 3), stop); });+ continue;+ }+ const auto processed = Timed(process_time, [&] {+ return ProcessDepotChunk(encrypted, grant.key, chunk.original_size, chunk.crc, chunk.sha, &plain);+ });+ if (processed == ChunkError::kNone) {+ compressed_bytes = encrypted.size(); result = InstallError::kNone; break;+ }+ ++server_cursor;+ if (attempt + 1 < attempts) ++corrupt_retries;+ result = InstallError::kCorrupt;+ }+ if (stop.load()) result = InstallError::kCanceled;+ if (result != InstallError::kNone) {+ detail = result == InstallError::kCanceled ? "canceled" : "chunk unavailable";+ if (result == InstallError::kNetwork && self->fetcher.last_failure) {+ const auto failure = self->fetcher.last_failure();+ if (!failure.empty()) detail += " " + failure;+ }+ }+ const auto cdn = self->fetcher.stats ? self->fetcher.stats() : CdnStats{};+ {+ std::lock_guard<std::mutex> lock(mutex);+ self->fetch = fetch_time; self->process = process_time; self->backoff = backoff_time;+ self->retries = retries; self->corrupt_retries = corrupt_retries; self->cdn = cdn;+ if (result != InstallError::kNone) { fail_locked(result, std::move(detail)); break; }+ self->plain = std::move(plain); self->compressed_bytes = compressed_bytes;+ self->ready = true;+ ++waiting;+ peak_waiting = std::max(peak_waiting, static_cast<std::uint32_t>(waiting));+ changed.notify_all();+ }}- ++server_cursor;- if (attempt + 1 < attempts) ++stats.corrupt_retries;- result = InstallError::kCorrupt;+#if defined(__cpp_exceptions)+ } catch (...) { publish_failure(InstallError::kNetwork, "chunk worker failed"); }+#endif+ };+ workers.push_back(std::move(worker));+ if (pthread_create(&self->thread, &attr, [](void* context) -> void* {+ static_cast<Worker*>(context)->run(); return nullptr;+ }, self) != 0) {+ publish_failure(InstallError::kNetwork, "cannot start workers"); break;+ }+ self->started = true;+ }+ if (attr_ready) pthread_attr_destroy(&attr);+ const auto prepare_file = [&](std::size_t index) {+ auto& work = files[index];+ if (work.prepared) return true;+ const auto& file = *work.placement.file;+ const auto path = target.install_root + "/" + file.path;+ if (file.is_directory()) {+ if (!Timed(create, [&] { return MakeDirs(path, &stats.folders_created); })) return false;+ } else {+ if (!Timed(create, [&] { return MakeDirs(Parent(path), &stats.folders_created); })) return false;+ const bool existed = Exists(path);+ if (file.chunks.empty() || !existed) {+ if (!Timed(create, [&] { return EnsureFileSize(path, file.size); })) return false;+ if (!existed) ++stats.files_created;}- if (result != InstallError::kNone) {- std::fclose(journal);- outcome.error = result;- outcome.detail = "chunk unavailable";- if (hooks_.last_failure && result == InstallError::kNetwork) outcome.detail += " " + hooks_.last_failure();- return outcome;+ }+ work.prepared = true;+ return true;+ };+ std::size_t prepare_next = 0, front_file = 0, written_chunks = 0;+ while (true) {+ if (cancel.load()) publish_failure(InstallError::kCanceled, "canceled");+ Worker* ready = nullptr;+ {+ std::lock_guard<std::mutex> lock(mutex);+ if (first_error != InstallError::kNone) break;+ for (auto& worker : workers) if (worker->ready) {+ ready = worker.get(); ready->ready = false; --waiting; break;}- if (progress.download_done == 0) trace("first-write");- if (!Timed(write, [&] { return WriteAt(path, file.size, chunk.offset, plain); })) { std::fclose(journal); return fail(InstallError::kStorage, "cannot write file"); }- Timed(journal_time, [&] {- std::fprintf(journal, "%s\n", entry.c_str());- std::fflush(journal);+ }+ snapshot();+ report_progress();+ if (ready) {+ const auto& work = chunks[ready->work];+ const auto& file = *files[work.file].placement.file;+ if (!prepare_file(work.file)) { publish_failure(InstallError::kStorage, "cannot create file"); break; }+ if (stats.chunks_done == 0) trace("first-write");+ const auto path = target.install_root + "/" + file.path;+ if (!Timed(write, [&] { return WriteAt(path, file.size, work.chunk->offset, ready->plain); })) {+ publish_failure(InstallError::kStorage, "cannot write file"); break;+ }+ const bool recorded = Timed(journal_time, [&] {+ return std::fprintf(journal, "%s\n", work.journal_key.c_str()) >= 0 && std::fflush(journal) == 0;});- ++stats.chunks_done;- stats.compressed_bytes += compressed_bytes;- stats.original_bytes += chunk.original_size;- progress.download_done += chunk.compressed_size;+ if (!recorded) { publish_failure(InstallError::kStorage, "cannot write journal"); break; }+ ++stats.chunks_done; ++written_chunks; --files[work.file].pending;+ stats.compressed_bytes += ready->compressed_bytes;+ stats.original_bytes += work.chunk->original_size;+ progress.download_done += work.chunk->compressed_size;if (on_progress) on_progress(progress);+ // Release the occupied slot only after its output has been written and freed.+ std::vector<std::uint8_t>().swap(ready->plain);+ {+ std::lock_guard<std::mutex> lock(mutex);+ ready->busy = false; --occupied; changed.notify_all();+ }+ continue;}+ while (front_file < files.size() && files[front_file].prepared && files[front_file].pending == 0) ++front_file;+ while (prepare_next < files.size() && files[prepare_next].prepared) ++prepare_next;+ if (prepare_next < files.size() && prepare_next - std::min(prepare_next, front_file) < static_cast<std::size_t>(ahead_files)) {+ if (!prepare_file(prepare_next++)) { publish_failure(InstallError::kStorage, "cannot create file"); break; }+ continue;+ }+ if (written_chunks == chunks.size() && prepare_next == files.size()) break;+ std::unique_lock<std::mutex> lock(mutex);+ changed.wait_for(lock, std::chrono::milliseconds(50), [&] { return stop.load() || waiting != 0; });+ }+ join_workers();+ if (first_error != InstallError::kNone) {+ outcome.error = first_error; outcome.detail = first_detail; outcome.progress = progress;+ return outcome;}std::fclose(journal);+ journal = nullptr;stats.download_ms = Milliseconds(Clock::now() - download_start);loop_finished = true;diff --git a/src/steam/backend/depot_installer.h b/src/steam/backend/depot_installer.hindex 89b4cf9..f714d18 100644--- a/src/steam/backend/depot_installer.h+++ b/src/steam/backend/depot_installer.h@@ -40,14 +40,24 @@ struct InstallProgress {std::uint32_t files_total = 0;};-// Wall-clock phases and summed write-loop stages; bytes exclude resumed journal entries.+struct DownloadTuning {+ int slots = 4;+ int ahead_files = 256;+};++// A missing or malformed file uses defaults; valid slot counts are clamped to 1..8.+DownloadTuning ReadDownloadTuning(const std::string& path);++// Wall-clock phases and summed stages; worker durations can exceed wall time.+// Bytes exclude resumed journal entries; peak_active counts occupied chunk slots (including waiting).struct InstallStats : CdnStats {std::uint64_t access_ms = 0, servers_ms = 0, manifests_ms = 0, prepare_ms = 0, download_ms = 0;std::uint64_t fetch_ms = 0, process_ms = 0, create_ms = 0, write_ms = 0, journal_ms = 0, backoff_ms = 0;std::uint64_t chunks_done = 0, chunks_skipped = 0, compressed_bytes = 0, original_bytes = 0;std::uint64_t files_created = 0, folders_created = 0, chunk_retries = 0, corrupt_retries = 0;std::uint64_t files_total = 0, download_total = 0, chunks_pending = 0, files_pending = 0, bytes_pending = 0;- std::uint32_t slots = 1, reuse = 1;+ std::uint32_t slots = 4, reuse = 1, ahead_files = 256;+ std::uint32_t peak_waiting = 0, peak_active = 0;};struct InstallOutcome {@@ -58,6 +68,14 @@ struct InstallOutcome {// Seams for tests; the defaults use CmClient, CdnClient and the real filesystem.struct InstallerHooks {+ struct ChunkFetcher {+ std::function<CdnError(const ContentServer&, std::uint32_t, const std::string&, std::size_t,+ const std::atomic<bool>&, std::vector<std::uint8_t>*)> fetch;+ std::function<std::string()> last_failure;+ std::function<CdnStats()> stats;+ };+ // Called once per worker; returned hooks are used and destroyed on that worker.+ std::function<ChunkFetcher()> make_fetcher;std::function<DepotAccessResult(const StoredSession&, std::uint32_t app_id,const std::vector<DepotRequest>&, const std::atomic<bool>&)> access;std::function<CdnError(std::uint32_t cell_id, const std::atomic<bool>&, std::vector<ContentServer>*)> servers;@@ -99,6 +117,9 @@ class DepotInstaller {public:void SetStats(std::function<void(const char*, const InstallStats&)> stats) { hooks_.stats = std::move(stats); }void SetTrace(std::function<void(const char*)> trace) { hooks_.trace = std::move(trace); }+ void SetTuning(DownloadTuning tuning) { tuning_ = tuning; }+ private:+ DownloadTuning tuning_;};// Removes a managed install directory: only paths under install_root, and only when it holdsdiff --git a/src/steam/backend/steam_install_runner.cpp b/src/steam/backend/steam_install_runner.cppindex 4a0c6dc..3448fc0 100644--- a/src/steam/backend/steam_install_runner.cpp+++ b/src/steam/backend/steam_install_runner.cpp@@ -18,6 +18,7 @@ std::string FormatInstallStats(const char* phase, const InstallStats& stats) {if (std::string(phase) == "shape") {add("chunks_pending", stats.chunks_pending); add("files_pending", stats.files_pending);add("bytes_pending", stats.bytes_pending);+ add("slots", stats.slots); add("ahead", stats.ahead_files);return detail;}add("dl_ms", stats.download_ms); add("cb", stats.compressed_bytes); add("ob", stats.original_bytes);@@ -29,6 +30,7 @@ std::string FormatInstallStats(const char* phase, const InstallStats& stats) {add("res", stats.resolve_ms); add("tcp", stats.connect_ms); add("tls", stats.tls_ms); add("ttfb", stats.first_byte_ms);add("retry", stats.chunk_retries); add("bad", stats.corrupt_retries);add("slots", stats.slots); add("reuse", stats.reuse);+ add("waiting", stats.peak_waiting); add("active", stats.peak_active);add("access", stats.access_ms); add("servers", stats.servers_ms); add("manifest", stats.manifests_ms); add("prep", stats.prepare_ms);add("http_ms", stats.total_ms); add("http_b", stats.bytes); add("fail", stats.failures);return detail;@@ -65,6 +67,7 @@ InstallRunner::Result SteamInstallRunner::Install(const StoredSession& session,const std::function<void(std::uint64_t, std::uint64_t)>& progress) {Result result;current_app_.store(id);+ installer_.SetTuning(tuning_ ? tuning_() : DownloadTuning{});auto log = [this, id](const char* step, const char* category, const char* detail) {if (log_) log_(id, step, category, detail);};diff --git a/src/steam/backend/steam_install_runner.h b/src/steam/backend/steam_install_runner.hindex ecd903a..3b909e1 100644--- a/src/steam/backend/steam_install_runner.h+++ b/src/steam/backend/steam_install_runner.h@@ -18,6 +18,7 @@ class SteamInstallRunner final : public InstallRunner {const std::atomic<bool>& cancel,const std::function<void(std::uint64_t, std::uint64_t)>& progress) override;bool Remove(const std::string& root) override;+ void SetTuning(std::function<DownloadTuning()> tuning) { tuning_ = std::move(tuning); }// Optional sanitized log: the Steam app ID, step, error category and a short detail; never// tokens or account identifiers. Called on the install worker.using LogFn = std::function<void(GameId app, const char* step, const char* category, const char* detail)>;@@ -36,6 +37,7 @@ class SteamInstallRunner final : public InstallRunner {CmClient& cm_;DepotInstaller installer_;LogFn log_;+ std::function<DownloadTuning()> tuning_;std::atomic<GameId> current_app_{0};};diff --git a/tests/depot_installer_test.cpp b/tests/depot_installer_test.cppindex 4753cc3..78de8e6 100644--- a/tests/depot_installer_test.cpp+++ b/tests/depot_installer_test.cpp@@ -6,6 +6,10 @@#include <mbedtls/sha1.h>#include <atomic>+#include <chrono>+#include <condition_variable>+#include <mutex>+#include <thread>#include <cstdio>#include <cstdlib>#include <filesystem>@@ -195,6 +199,332 @@ World MakeWorld() {return world;}+void OverlapsFourFetches(const std::filesystem::path& root) {+ auto world = MakeWorld();+ world.manifests[441].files = {world.AddFile("parallel", {"a", "b", "c", "d", "e", "f", "g", "h"})};+ world.manifests[442].files.clear();+ auto hooks = world.Hooks();+ std::mutex mutex;+ std::condition_variable changed;+ int active = 0, peak = 0, entered = 0;+ hooks.chunk = [&](const ContentServer&, std::uint32_t, const std::string& sha, std::size_t,+ const std::atomic<bool>&, std::vector<std::uint8_t>* out) {+ std::unique_lock<std::mutex> lock(mutex);+ ++active; ++entered;+ peak = std::max(peak, active);+ changed.notify_all();+ changed.wait_for(lock, std::chrono::milliseconds(250), [&] { return entered >= 4; });+ lock.unlock();+ *out = world.served.at(sha);+ lock.lock();+ --active;+ return CdnError::kNone;+ };+ DepotInstaller installer(hooks);+ std::atomic<bool> cancel{false};+ const auto outcome = installer.Run({}, Target(root), cancel);+ CHECK(outcome.error == InstallError::kNone);+ CHECK(peak == 4);+ CHECK(Read(root / "parallel") == "abcdefgh");+}++struct ParallelFixture {+ World world = MakeWorld();+ std::mutex mutex;+ std::condition_variable changed;+ int entered = 0, finished = 0, active = 0, peak = 0, factories = 0, pauses = 0;+ bool release = false, hold_first = false, fail_first = false, corrupt_first = false, backoff = false;+ std::atomic<int> callbacks{0}, written{0};+ InstallStats last;+ std::string first_sha;+ ParallelFixture() {+ world.manifests[441].files = {world.AddFile("parallel", {"a", "b", "c", "d", "e", "f", "g", "h"})};+ world.manifests[442].files.clear();+ first_sha = HexOf(world.manifests[441].files[0].chunks[0].sha);+ }+ bool Wait(const std::function<bool()>& predicate) {+ std::unique_lock<std::mutex> lock(mutex);+ return changed.wait_for(lock, std::chrono::seconds(3), predicate);+ }+ void Release() {+ std::lock_guard<std::mutex> lock(mutex);+ release = true; changed.notify_all();+ }+ InstallerHooks Hooks(int invalid_factory = -1) {+ auto hooks = world.Hooks();+ hooks.make_fetcher = [this, invalid_factory] {+ const int number = ++factories;+ InstallerHooks::ChunkFetcher fetcher;+ if (number == invalid_factory) return fetcher;+ struct State {+ std::thread::id owner;+ std::uint64_t requests = 0;+ int corruptions = 0;+ ~State() { CHECK(owner == std::thread::id{} || owner == std::this_thread::get_id()); }+ };+ auto state = std::make_shared<State>();+ fetcher.fetch = [this, state](const ContentServer&, std::uint32_t, const std::string& sha, std::size_t,+ const std::atomic<bool>& stop, std::vector<std::uint8_t>* out) {+ if (state->owner == std::thread::id{}) state->owner = std::this_thread::get_id();+ CHECK(state->owner == std::this_thread::get_id());+ ++state->requests;+ std::unique_lock<std::mutex> lock(mutex);+ ++entered; ++active; peak = std::max(peak, active); changed.notify_all();+ const bool first = sha == first_sha;+ while (!stop.load() && !(backoff || (fail_first && first && entered >= 4) || (release && (!hold_first || !first))))+ changed.wait_for(lock, std::chrono::milliseconds(10));+ CdnError error = CdnError::kNone;+ if (stop.load()) error = CdnError::kCanceled;+ else if (backoff || (fail_first && first)) error = CdnError::kNetwork;+ else {+ *out = world.served.at(sha);+ if (corrupt_first && first && state->corruptions++ == 0) out->back() ^= 0xff;+ }+ --active; ++finished; changed.notify_all();+ return error;+ };+ fetcher.last_failure = [state] {+ CHECK(state->owner == std::this_thread::get_id());+ return std::string("http=503");+ };+ fetcher.stats = [state] {+ CHECK(state->owner == std::this_thread::get_id());+ CdnStats stats; stats.requests = state->requests; return stats;+ };+ return fetcher;+ };+ hooks.pause = [this](int, const std::atomic<bool>& stop) {+ if (!backoff) return;+ std::unique_lock<std::mutex> lock(mutex);+ ++pauses; changed.notify_all();+ while (!stop.load()) changed.wait_for(lock, std::chrono::milliseconds(10));+ };+ hooks.stats = [this](const char* phase, const InstallStats& stats) {+ ++callbacks;+ if (std::string(phase) == "end") { CHECK(active == 0); last = stats; }+ };+ return hooks;+ }+};++void OutOfOrderAndBoundedResults(const std::filesystem::path& root) {+ ParallelFixture fixture;+ fixture.hold_first = true;+ auto hooks = fixture.Hooks();+ const auto coordinator = std::this_thread::get_id();+ DepotInstaller installer(hooks);+ std::atomic<bool> cancel{false};+ InstallOutcome outcome;+ std::uint64_t previous = 0;+ bool block_callback = true;+ std::thread caller([&] {+ const auto owner = std::this_thread::get_id();+ outcome = installer.Run({}, Target(root), cancel, [&](const InstallProgress& progress) {+ CHECK(std::this_thread::get_id() == owner && owner != coordinator);+ CHECK(progress.download_done >= previous); previous = progress.download_done;+ ++fixture.callbacks;+ if (progress.download_done == 0) return;+ ++fixture.written;+ std::unique_lock<std::mutex> lock(fixture.mutex);+ fixture.changed.notify_all();+ while (block_callback) fixture.changed.wait(lock);+ });+ });+ CHECK(fixture.Wait([&] { return fixture.entered == 4; }));+ fixture.Release();+ CHECK(fixture.Wait([&] { return fixture.finished == 3 && fixture.written == 1; }));+ {+ std::lock_guard<std::mutex> lock(fixture.mutex);+ CHECK(fixture.entered == 4); // the writing result still owns its slot+ CHECK(Read(root / "parallel")[0] == '\0'); // first chunk remains in flight+ fixture.hold_first = false; block_callback = false; fixture.changed.notify_all();+ }+ caller.join();+ CHECK(outcome.error == InstallError::kNone);+ CHECK(Read(root / "parallel") == "abcdefgh");+ CHECK(outcome.progress.download_done == outcome.progress.download_total);+ CHECK(fixture.last.requests == 8 && fixture.last.chunks_done == 8);+ CHECK(fixture.last.peak_active == 4 && fixture.last.peak_waiting <= 4 && fixture.last.peak_waiting >= 1);+}++void EightSlotsAndShape(const std::filesystem::path& root) {+ ParallelFixture fixture;+ auto hooks = fixture.Hooks();+ const auto stats = hooks.stats;+ hooks.stats = [&](const char* phase, const InstallStats& value) {+ stats(phase, value);+ if (std::string(phase) == "shape") {+ const auto detail = FormatInstallStats(phase, value);+ CHECK(detail.find("slots=8") != std::string::npos && detail.find("ahead=5") != std::string::npos);+ }+ };+ DepotInstaller installer(hooks);+ installer.SetTuning({8, 5});+ std::atomic<bool> cancel{false};+ InstallOutcome result;+ std::thread caller([&] { result = installer.Run({}, Target(root), cancel); });+ CHECK(fixture.Wait([&] { return fixture.entered == 8; }));+ fixture.Release();+ caller.join();+ CHECK(result.error == InstallError::kNone && fixture.peak == 8 && fixture.last.peak_active == 8);+ CHECK(Read(root / "parallel") == "abcdefgh");+}++void CancelStopsAllWorkers(const std::filesystem::path& root, bool during_backoff) {+ ParallelFixture fixture;+ fixture.backoff = during_backoff;+ DepotInstaller installer(fixture.Hooks());+ std::atomic<bool> cancel{false};+ InstallOutcome outcome;+ std::thread caller([&] {+ outcome = installer.Run({}, Target(root), cancel, [&](const InstallProgress&) { ++fixture.callbacks; });+ });+ CHECK(fixture.Wait([&] { return during_backoff ? fixture.pauses == 4 : fixture.entered == 4; }));+ cancel.store(true);+ caller.join();+ CHECK(outcome.error == InstallError::kCanceled && fixture.active == 0);+ CHECK(fixture.last.chunks_done == 0);+ const auto calls = fixture.callbacks.load();+ const auto fetches = fixture.entered;+ usleep(20000);+ CHECK(fixture.callbacks == calls && fixture.entered == fetches);+ CHECK(Read(root / DepotInstaller::kJournalDir / "journal").empty());+}++void WorkerFailureWinsAndJoins(const std::filesystem::path& root) {+ ParallelFixture fixture;+ fixture.fail_first = true;+ DepotInstaller installer(fixture.Hooks());+ std::atomic<bool> cancel{false};+ const auto result = installer.Run({}, Target(root), cancel);+ CHECK(result.error == InstallError::kNetwork && result.detail == "chunk unavailable http=503");+ CHECK(fixture.active == 0 && fixture.last.chunks_done == 0);+ CHECK(fixture.last.chunk_retries == 5);+}++void InvalidFactoryJoinsStartedWorkers(const std::filesystem::path& root) {+ ParallelFixture fixture;+ DepotInstaller installer(fixture.Hooks(3));+ std::atomic<bool> cancel{false};+ const auto result = installer.Run({}, Target(root), cancel);+ CHECK(result.error == InstallError::kNetwork && result.detail == "cannot create fetcher");+ CHECK(fixture.factories == 3 && fixture.active == 0);+}++void WriteFailureStopsWorkers(const std::filesystem::path& root) {+ ParallelFixture fixture;+ DepotInstaller installer(fixture.Hooks());+ std::atomic<bool> cancel{false};+ InstallOutcome outcome;+ std::thread caller([&] { outcome = installer.Run({}, Target(root), cancel); });+ CHECK(fixture.Wait([&] { return fixture.entered == 4; }));+ // Wait for the coordinator to prepare the file while all fetches are blocked.+ for (int tries = 0; tries < 300 && !std::filesystem::exists(root / "parallel"); ++tries) usleep(10000);+ CHECK(std::filesystem::is_regular_file(root / "parallel"));+ std::filesystem::remove(root / "parallel");+ std::filesystem::create_directory(root / "parallel");+ fixture.Release();+ caller.join();+ CHECK(outcome.error == InstallError::kStorage && outcome.detail == "cannot write file");+ CHECK(fixture.active == 0 && fixture.last.chunks_done == 0);+ CHECK(Read(root / DepotInstaller::kJournalDir / "journal").empty());+}++void ParallelCorruptRetryAndResume(const std::filesystem::path& root) {+ ParallelFixture fixture;+ fixture.corrupt_first = true;+ fixture.Release();+ DepotInstaller installer(fixture.Hooks());+ std::atomic<bool> cancel{false};+ CHECK(installer.Run({}, Target(root), cancel).error == InstallError::kNone);+ CHECK(fixture.last.corrupt_retries == 1 && fixture.last.chunk_retries == 1 && fixture.last.requests == 9);+ CHECK(Read(root / "parallel") == "abcdefgh");+ const auto resumed_root = root / "resumed";+ std::filesystem::create_directories(resumed_root / DepotInstaller::kJournalDir);+ std::ofstream(resumed_root / "parallel", std::ios::binary) << "a_c_e_g_";+ std::ofstream journal(resumed_root / DepotInstaller::kJournalDir / "journal");+ for (int offset : {0, 2, 4, 6}) journal << "441\t" << offset << "\tparallel\n";+ journal.close();+ fixture.corrupt_first = false;+ fixture.entered = fixture.finished = 0;+ CHECK(installer.Run({}, Target(resumed_root), cancel).error == InstallError::kNone);+ CHECK(fixture.entered == 4 && fixture.last.requests == 4 && fixture.last.chunks_skipped == 4);+ CHECK(Read(resumed_root / "parallel") == "abcdefgh");+}++void FileCreationAheadIsBounded(const std::filesystem::path& root) {+ ParallelFixture fixture;+ fixture.world.manifests[441].files.clear();+ for (int index = 0; index < 20; ++index)+ fixture.world.manifests[441].files.push_back(fixture.world.AddFile("folder/f" + std::to_string(100 + index), {std::to_string(index)}));+ DepotInstaller installer(fixture.Hooks());+ installer.SetTuning({4, 3});+ std::atomic<bool> cancel{false};+ InstallOutcome outcome;+ std::thread caller([&] { outcome = installer.Run({}, Target(root), cancel); });+ CHECK(fixture.Wait([&] { return fixture.entered == 4; }));+ usleep(80000);+ int count = 0;+ for (const auto& entry : std::filesystem::directory_iterator(root / "folder")) if (entry.is_regular_file()) ++count;+ CHECK(count == 3);+ fixture.Release();+ caller.join();+ CHECK(outcome.error == InstallError::kNone && fixture.last.chunks_done == 20);+}++void ParallelMergedAndFullyResumed(const std::filesystem::path& root) {+ auto world = MakeWorld();+ auto hooks = world.Hooks();+ const auto original = hooks.chunk;+ std::mutex mutex;+ hooks.chunk = [&](const ContentServer& server, std::uint32_t depot, const std::string& sha, std::size_t cap,+ const std::atomic<bool>& stop, std::vector<std::uint8_t>* out) {+ std::lock_guard<std::mutex> lock(mutex);+ return original(server, depot, sha, cap, stop, out);+ };+ DepotInstaller installer(hooks);+ std::atomic<bool> cancel{false};+ CHECK(installer.Run({}, Target(root), cancel).error == InstallError::kNone);+ CHECK(Read(root / "game.exe") == "MZ-executable-second-chunk");+ CHECK(Read(root / "data/level.dat") == "level-patched");+ CHECK(world.chunk_calls == 3 && std::filesystem::file_size(root / "empty.txt") == 0);+ const auto resumed = root / "resumed";+ std::filesystem::create_directories(resumed / DepotInstaller::kJournalDir);+ std::filesystem::create_directories(resumed / "data");+ std::ofstream(resumed / "game.exe") << "MZ-executable-second-chunk";+ // On a case-sensitive filesystem make the chosen mixed-case parent too.+ std::filesystem::create_directories(resumed / "DATA");+ std::ofstream(resumed / "DATA/level.dat") << "level-patched";+ std::ofstream journal(resumed / DepotInstaller::kJournalDir / "journal");+ journal << "441\t0\tgame.exe\n441\t14\tgame.exe\n442\t0\tDATA/level.dat\n";+ journal.close();+ int factories = 0;+ hooks.make_fetcher = [&] { ++factories; return InstallerHooks::ChunkFetcher{}; };+ DepotInstaller fully_resumed(hooks);+ CHECK(fully_resumed.Run({}, Target(resumed), cancel).error == InstallError::kNone);+ CHECK(factories == 0 && std::filesystem::file_size(resumed / "empty.txt") == 0);+ CHECK(Read(resumed / "game.exe") == "MZ-executable-second-chunk");+}++void TuningFileDefaultsAndValidation(const std::filesystem::path& root) {+ std::filesystem::create_directories(root);+ const auto path = (root / "tuning").string();+ auto tuning = ReadDownloadTuning(path);+ CHECK(tuning.slots == 4 && tuning.ahead_files == 256);+ std::ofstream(path) << "slots=8\nahead=12\n";+ tuning = ReadDownloadTuning(path);+ CHECK(tuning.slots == 8 && tuning.ahead_files == 12);+ std::ofstream(path) << "slots=99\n";+ CHECK(ReadDownloadTuning(path).slots == 8);+ std::ofstream(path) << "slots=0\n";+ CHECK(ReadDownloadTuning(path).slots == 1);+ for (const auto text : {"slots=8\nahead=-1\n", "slots=abc\n", "slots=8garbage\n", "unknown=1\n", "slots=8\nslots=1\n"}) {+ std::ofstream(path) << text;+ tuning = ReadDownloadTuning(path);+ CHECK(tuning.slots == 4 && tuning.ahead_files == 256);+ }+}+void CountsActualUsefulCompressedBytes(const std::filesystem::path& root) {auto world = MakeWorld();// HTTP permits the advertised size plus padding; a verified body can differ from metadata.@@ -213,6 +543,7 @@ void CountsActualUsefulCompressedBytes(const std::filesystem::path& root) {InstallStats last;hooks.stats = [&](const char* phase, const InstallStats& stats) { if (std::string(phase) == "end") last = stats; };DepotInstaller installer(hooks);+ installer.SetTuning({1, 256});std::atomic<bool> cancel{false};const auto outcome = installer.Run({}, Target(root), cancel);CHECK(outcome.error == InstallError::kNone);@@ -228,6 +559,7 @@ void StorageFailureEndsStats(const std::filesystem::path& root) {int ends = 0;hooks.stats = [&](const char* phase, const InstallStats&) { if (std::string(phase) == "end") ++ends; };DepotInstaller installer(hooks);+ installer.SetTuning({1, 256});std::atomic<bool> cancel{false};CHECK(installer.Run({}, Target(root), cancel).error == InstallError::kStorage);CHECK(ends == 1);@@ -292,6 +624,7 @@ void RunStats(const std::filesystem::path& base) {return fetch(server, depot, sha, cap, canceled, out);};DepotInstaller installer(hooks);+ installer.SetTuning({1, 256});auto target = Target(base / std::to_string(mode));const auto outcome = installer.Run({}, target, cancel);CHECK(ends == 1 && shapes == 1 && last.requests == static_cast<std::uint64_t>(world.chunk_calls));@@ -318,6 +651,7 @@ void RunStats(const std::filesystem::path& base) {void InstallsMergedDepotsAndWritesRecord(const std::filesystem::path& root) {auto world = MakeWorld();DepotInstaller installer(world.Hooks());+ installer.SetTuning({1, 256});std::atomic<bool> cancel{false};InstallProgress last;const auto outcome = installer.Run({}, Target(root), cancel, [&](const InstallProgress& progress) { last = progress; });@@ -340,6 +674,7 @@ void ResumesWithoutRefetchingFinishedChunks(const std::filesystem::path& root) {world.cancel = &cancel;world.cancel_after = 2;DepotInstaller installer(world.Hooks());+ installer.SetTuning({1, 256});const auto first = installer.Run({}, Target(root), cancel);CHECK(first.error == InstallError::kCanceled);CHECK(std::filesystem::exists(root / DepotInstaller::kJournalDir));@@ -357,6 +692,7 @@ void RefusesWhenSpaceIsShort(const std::filesystem::path& root) {auto world = MakeWorld();world.free_bytes = 1024;DepotInstaller installer(world.Hooks());+ installer.SetTuning({1, 256});std::atomic<bool> cancel{false};CHECK(installer.Run({}, Target(root), cancel).error == InstallError::kNoSpace);CHECK(world.chunk_calls == 0);@@ -366,6 +702,7 @@ void CorruptChunksFailAfterRetries(const std::filesystem::path& root) {auto world = MakeWorld();world.corrupt = true;DepotInstaller installer(world.Hooks());+ installer.SetTuning({1, 256});std::atomic<bool> cancel{false};CHECK(installer.Run({}, Target(root), cancel).error == InstallError::kCorrupt);CHECK(world.chunk_calls == DepotInstaller::kChunkAttempts * 2);@@ -378,6 +715,7 @@ void BusyCdnIsRetriedAfterAWait(const std::filesystem::path& root) {std::vector<int> waits;hooks.pause = [&](int milliseconds, const std::atomic<bool>&) { waits.push_back(milliseconds); };DepotInstaller installer(std::move(hooks));+ installer.SetTuning({1, 256});std::atomic<bool> cancel{false};CHECK(installer.Run({}, Target(root), cancel).error == InstallError::kNone);CHECK((waits == std::vector<int>{1000, 2000, 4000}));@@ -399,6 +737,7 @@ void BrokenManifestIsFetchedAgainElsewhere(const std::filesystem::path& root) {std::vector<int> waits;hooks.pause = [&](int milliseconds, const std::atomic<bool>&) { waits.push_back(milliseconds); };DepotInstaller installer(std::move(hooks));+ installer.SetTuning({1, 256});std::atomic<bool> cancel{false};CHECK(installer.Run({}, Target(root / "recovers"), cancel).error == InstallError::kNone);CHECK((waits == std::vector<int>{1000, 2000}));@@ -411,6 +750,7 @@ void BrokenManifestIsFetchedAgainElsewhere(const std::filesystem::path& root) {};failing.pause = [](int, const std::atomic<bool>&) {};DepotInstaller stuck(std::move(failing));+ stuck.SetTuning({1, 256});CHECK(stuck.Run({}, Target(root / "stuck"), cancel).error == InstallError::kNetwork);CHECK(tries == 4);}@@ -433,6 +773,18 @@ void RemovesOnlyManagedFolders(const std::filesystem::path& base) {int main() {const auto base = std::filesystem::temp_directory_path() / ("playden-installer-test-" + std::to_string(::getpid()));std::filesystem::remove_all(base);+ OverlapsFourFetches(base / "parallel");+ OutOfOrderAndBoundedResults(base / "out-of-order");+ EightSlotsAndShape(base / "eight-slots");+ CancelStopsAllWorkers(base / "cancel-fetch", false);+ CancelStopsAllWorkers(base / "cancel-backoff", true);+ WorkerFailureWinsAndJoins(base / "worker-failure");+ InvalidFactoryJoinsStartedWorkers(base / "factory-failure");+ WriteFailureStopsWorkers(base / "write-failure");+ ParallelCorruptRetryAndResume(base / "parallel-resume");+ FileCreationAheadIsBounded(base / "ahead");+ TuningFileDefaultsAndValidation(base / "tuning");+ ParallelMergedAndFullyResumed(base / "parallel-merged");CountsActualUsefulCompressedBytes(base / "actual-compressed");StorageFailureEndsStats(base / "storage-stats");StatsAndRemovalLogs(base / "removal");