From c3a4029a299edae0514c3478661d4ffb2d607e9e Mon Sep 17 00:00:00 2001 From: t <294862818+tcz0g@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:41:34 +0100 Subject: [PATCH 1/2] feat(archives): report measured progress for extract and compress rows --- docs/design/file-jobs.md | 2 +- docs/user/file-operations.md | 2 +- src/app/job_activity.cpp | 68 ++++++++++++++++++------- src/operations/archive_reader.cpp | 24 +++++++++ src/operations/archive_service.cpp | 15 ++++++ src/operations/archive_service.h | 4 ++ src/operations/archive_work.h | 3 ++ src/operations/archive_writer.cpp | 46 +++++++++++++++++ tests/archive_service_test.cpp | 81 ++++++++++++++++++++++++++++++ tests/operation_activity_test.cpp | 57 ++++++++++++++++++++- 10 files changed, 280 insertions(+), 22 deletions(-) diff --git a/docs/design/file-jobs.md b/docs/design/file-jobs.md index 802b8ff1..2616aa8b 100644 --- a/docs/design/file-jobs.md +++ b/docs/design/file-jobs.md @@ -12,7 +12,7 @@ Keep captured destinations and target identities throughout preparation, conflic The [operations controller](../../src/app/page/operations_controller.h) owns a toolbar indicator, anchored scrollable popover and centered report inspector. While every running job knows its progress, the indicator draws their average as a thin bar along its bottom edge, and the popover fits its height to its rows up to a window-relative limit. The [operations view](../../src/ui/controls/operations_view.h) composes actual Noctalia Button, ProgressBar and ScrollView controls. It builds one row per job, never per file. Running transfer rows show speed, a 6px progress bar with tabular percentage, compact byte/file totals, remaining time, current item, Details and Cancel inline; finished rows show their outcome and Details. Service events update indicators globally. A 200 ms progress timer runs while jobs are preparing or working and the popover or a shown toolbar indicator draws them, or while the details dialog follows a live job; row identities remain stable during progress updates, and the dialog rewrites its labels and bar in place instead of rebuilding. Scene structure changes occur in Layout and cancel stale pointer captures. Closing presentation releases controls/timers without cancelling accepted jobs. A parent size change dismisses the toolbar popover, avoiding repositioning against stale parent/output geometry; reopening measures against the committed window size. -Only genuinely known totals produce progress fractions. Transfers measure their sources on the worker before streaming payload bytes across local disks, mounted network shares, phones/cameras and remote GIO providers so byte totals, percentage, file counts, live speed and smoothed remaining time are measured rather than assumed; network and remote provider directory scans obey both entry/depth limits and a short time budget so a huge remote tree falls back to an honest lower bound instead of stalling the transfer start, while phones and cameras list in full within the entry limit, since a USB listing is slow but finite. Native sources use the shared folder walk, without counting link target lengths a transfer never writes. Provider copies count each regular file once its copy is verified, so links and special entries in a provider tree leave the total a lower bound. Once transferred bytes surpass a partial lower bound, the bar drops its fraction instead of claiming 100%, and running fractions stay below 100% until all bytes land. A move that stays on one device renames instead of streaming payload, a link transfer writes no payload, history replay re-runs recorded effects, removable-media device flush has no measurable writeback denominator, and archive counters have no reliable final denominator, so those phases stay indeterminate. A native copy or move job parks its worker at the next scan measurement, walk entry, copy chunk or staging checkpoint when paused, and the park releases on resume or cancellation; provider transfers, link transfers, history replay and the terminal flush offer no pause. Pause is not rollback: already published effects stay, and terminal summaries still distinguish failed, partial, cancelled, skipped and completed effects. Cancellation is not rollback. Reports use literal UTF-8 text and explicit truncation. Finished reports survive ordinary job pruning; the popover header's Clear removes reports, not jobs. +Only genuinely known totals produce progress fractions. Transfers measure their sources on the worker before streaming payload bytes across local disks, mounted network shares, phones/cameras and remote GIO providers so byte totals, percentage, file counts, live speed and smoothed remaining time are measured rather than assumed; network and remote provider directory scans obey both entry/depth limits and a short time budget so a huge remote tree falls back to an honest lower bound instead of stalling the transfer start, while phones and cameras list in full within the entry limit, since a USB listing is slow but finite. Native sources use the shared folder walk, without counting link target lengths a transfer never writes. Provider copies count each regular file once its copy is verified, so links and special entries in a provider tree leave the total a lower bound. Once transferred bytes surpass a partial lower bound, the bar drops its fraction instead of claiming 100%, and running fractions stay below 100% until all bytes land. A move that stays on one device renames instead of streaming payload, a link transfer writes no payload, history replay re-runs recorded effects and removable-media device flush has no measurable writeback denominator, so those phases stay indeterminate. Archive extraction takes its denominator from the validated member catalog before payload is written, and compression pre-scans its sources before opening the output; the compression pre-scan is its own archive-limited pass rather than the transfer estimator's shared folder walker, because entry/depth limits and special-file refusal differ there, the compressed result size exists only when the job ends, so it is never a progress denominator, raw single-file formats with unknown uncompressed sizes and provider-run unpacking keep those byte totals withheld, batch rows keep their per-archive fraction, and a source that grows past the compression pre-scan total turns that total into a lower bound whose fraction the row drops, exactly as a transfer's bounded partial scan does. A native copy or move job parks its worker at the next scan measurement, walk entry, copy chunk or staging checkpoint when paused, and the park releases on resume or cancellation; provider transfers, link transfers, history replay and the terminal flush offer no pause. Pause is not rollback: already published effects stay, and terminal summaries still distinguish failed, partial, cancelled, skipped and completed effects. Cancellation is not rollback. Reports use literal UTF-8 text and explicit truncation. Finished reports survive ordinary job pruning; the popover header's Clear removes reports, not jobs. Actions retain a JobId and revalidate it. Review/Retry route to the job's current owning page through the workspace, including reassignment after tab closure. Existing conflict/password dialogs remain authoritative. Transfer retry stays in TransferController, including its asynchronous clipboard revision claim and finishMove safeguards. Details capture an immutable report; copying it cannot refer to a recycled row. Only finished jobs that failed, ended partial or were cancelled offer that dialog: it shows the fixed snapshot it was opened from, every measured field and the report. A running row already shows its live progress, and a clean success shows its outcome on the row, with the elapsed time its own service measured, which a job loaded from history never has. diff --git a/docs/user/file-operations.md b/docs/user/file-operations.md index 31d5199a..e0e5f976 100644 --- a/docs/user/file-operations.md +++ b/docs/user/file-operations.md @@ -79,7 +79,7 @@ Choose **Regex** to replace every match of an ECMAScript regular expression. In ## File Operations popover -The toolbar **File Operations** button shows a busy glyph while jobs run, with a thin bar along its bottom edge while every running job's progress is known; its tooltip names the job or counts the active ones. Open it, or use **File Operations** in the main menu, to see every tab and window of this Luciole inline: progress bar and percentage, bytes transferred, transfer speed, file counts, remaining time, current item, pending decisions and results. Copy and move jobs measure their sources first across local folders, phones and cameras, mounted network shares and remote locations, falling back to a lower bound if a large remote tree hits the scan limit. A move that stays on the same drive renames the folder instead of copying it, and jobs with no byte payload (such as creating links) track item progress once multiple items complete or omit the bar for a single item. +The toolbar **File Operations** button shows a busy glyph while jobs run, with a thin bar along its bottom edge while every running job's progress is known; its tooltip names the job or counts the active ones. Open it, or use **File Operations** in the main menu, to see every tab and window of this Luciole inline: progress bar and percentage, bytes transferred, transfer speed, file counts, remaining time, current item, pending decisions and results. Copy and move jobs measure their sources first across local folders, phones and cameras, mounted network shares and remote locations, falling back to a lower bound if a large remote tree hits the scan limit. A move that stays on the same drive renames the folder instead of copying it, and jobs with no byte payload (such as creating links) track item progress once multiple items complete or omit the bar for a single item. Extract and Compress jobs measure against the archive listing and the source files, showing byte and entry totals whenever they are knowable, see [archives](archives.md). Running rows show their actions as icons; hover one for its name. diff --git a/src/app/job_activity.cpp b/src/app/job_activity.cpp index 42e26f8d..78bacbb6 100644 --- a/src/app/job_activity.cpp +++ b/src/app/job_activity.cpp @@ -215,19 +215,22 @@ namespace { return {formatted, {}}; } // Compact byte ratio for the inline row ("5.9 / 12.3 GiB", or "48.2 GiB / 1.4 TiB+"). - std::string compactBytesText(const luciole::TransferProgress& measured) { - const std::string done = sizeText(measured.bytes); - if (!measured.bytesTotal || !*measured.bytesTotal) { - return i18n::tr("app.job-activity.size-transferred", "size", done); - } - const std::string total = sizeText(*measured.bytesTotal); - const auto [doneVal, doneUnit] = splitSizeUnit(done); - const auto [totalVal, totalUnit] = splitSizeUnit(total); - const char* plus = measured.partial ? "+" : ""; + std::string compactBytesText(std::uint64_t done, const std::optional& total, bool partial) { + const std::string doneText = sizeText(done); + if (!total || !*total) { + return i18n::tr("app.job-activity.size-transferred", "size", doneText); + } + const std::string totalText = sizeText(*total); + const auto [doneVal, doneUnit] = splitSizeUnit(doneText); + const auto [totalVal, totalUnit] = splitSizeUnit(totalText); + const char* suffix = partial ? "+" : ""; if (!doneUnit.empty() && doneUnit == totalUnit) { - return std::format("{} / {}{}{}", doneVal, totalVal, totalUnit, plus); + return std::format("{} / {}{}{}", doneVal, totalVal, totalUnit, suffix); } - return std::format("{} / {}{}", done, total, plus); + return std::format("{} / {}{}", doneText, totalText, suffix); + } + std::string compactBytesText(const luciole::TransferProgress& measured) { + return compactBytesText(measured.bytes, measured.bytesTotal, measured.partial); } // Compact file count for the inline row; hides noisy "0/1 files" on single-file transfers. std::string compactFilesText(const luciole::TransferProgress& measured) { @@ -478,32 +481,35 @@ namespace { activity.title = service.archiveCount() ? i18n::tr("app.job-activity.extract-archives") : i18n::tr("app.job-activity.archive-operation"); if (job.running()) { - switch (service.phase()) { + const auto phase = service.phase(); + std::string phaseLabel; + switch (phase) { case luciole::ArchivePhase::Reading: - activity.summary = i18n::tr("app.job-activity.reading-archive"); + phaseLabel = i18n::tr("app.job-activity.reading-archive"); break; case luciole::ArchivePhase::Compressing: - activity.summary = i18n::tr("app.job-activity.compressing"); + phaseLabel = i18n::tr("app.job-activity.compressing"); break; case luciole::ArchivePhase::Extracting: - activity.summary = i18n::tr("app.job-activity.extracting"); + phaseLabel = i18n::tr("app.job-activity.extracting"); break; case luciole::ArchivePhase::Transferring: - activity.summary = service.flushPhase() == luciole::TransferFlush::None + phaseLabel = service.flushPhase() == luciole::TransferFlush::None ? i18n::tr("app.job-activity.publishing-output") : i18n::tr("app.job-activity.writing-to-device"); break; case luciole::ArchivePhase::Cleaning: - activity.summary = i18n::tr("app.job-activity.cleaning-up"); + phaseLabel = i18n::tr("app.job-activity.cleaning-up"); break; case luciole::ArchivePhase::WaitingPassword: - activity.summary = i18n::tr("app.job-activity.waiting-for-password"); + phaseLabel = i18n::tr("app.job-activity.waiting-for-password"); activity.canReview = true; break; case luciole::ArchivePhase::Idle: - activity.summary = i18n::tr("app.job-activity.preparing"); + phaseLabel = i18n::tr("app.job-activity.preparing"); break; } + activity.summary = phaseLabel; activity.summary += " · " + i18n::trp("app.job-activity.count-entries-size-processed", static_cast(service.items()), "size", sizeText(service.bytes())); @@ -523,6 +529,30 @@ namespace { ); activity.progress = ratio; activity.progressText = percentText(ratio, service.completedArchives() >= service.archiveCount()); + } else if (phase == luciole::ArchivePhase::Extracting || phase == luciole::ArchivePhase::Compressing) { + const auto totalBytes = service.totalBytes(); + const auto totalItems = service.totalItems(); + if (totalBytes || totalItems) { + activity.statusRight = phaseLabel; + const bool surpassed = totalBytes && service.bytes() > totalBytes; + std::string left = totalBytes && !surpassed + ? compactBytesText(service.bytes(), totalBytes, false) + : i18n::tr("app.job-activity.size-transferred", "size", sizeText(service.bytes())); + if (totalItems) { + const auto done = std::min( + phase == luciole::ArchivePhase::Compressing ? service.items() : service.completedItems(), totalItems + ); + left += + " · " + i18n::trp("app.job-activity.done-of-count-items", static_cast(totalItems), "done", done); + } + activity.detailLeft = std::move(left); + if (totalBytes && !surpassed) { + const float ratio = + std::clamp(static_cast(service.bytes()) / static_cast(totalBytes), 0.0F, 1.0F); + activity.progress = ratio; + activity.progressText = percentText(ratio, service.bytes() >= totalBytes); + } + } } activity.state = activity.canReview ? ActivityState::Waiting : ActivityState::Working; } else if (!service.results().empty()) { diff --git a/src/operations/archive_reader.cpp b/src/operations/archive_reader.cpp index c471db5d..301f4ddb 100644 --- a/src/operations/archive_reader.cpp +++ b/src/operations/archive_reader.cpp @@ -624,6 +624,26 @@ namespace { fs::remove_all(directory, ignored); work.progress.bytes.store(total); } + void publishExtractionTotals( + Work& work, const ArchiveCatalog& contents, const std::map& entries, + const std::set& wanted, const std::set& bodies, bool providerRun + ) { + if (providerRun) { + return; + } + std::uint64_t selectedBytes = 0; + bool sizesKnown = true; + for (const auto& path : bodies) { + const auto& size = contents.entries[entries.at(path)].size; + if (!size || *size > UINT64_MAX - selectedBytes) { + sizesKnown = false; + continue; + } + selectedBytes += *size; + } + work.progress.totalBytes.store(sizesKnown ? selectedBytes : 0); + work.progress.totalItems.store(wanted.size()); + } } // namespace luciole::archive_work::Prepared luciole::archive_work::inspect( @@ -747,6 +767,7 @@ luciole::archive_work::Prepared luciole::archive_work::extract( for (const auto& path : bodies) { addSize(stagingBytes, dataSize(path)); } + publishExtractionTotals(work, *contents, entries, wanted, bodies, reader.nativeSevenZip()); requireSpace(data.get(), stagingBytes); if (!open) { const auto parent = opened(::open(destinationParent.c_str(), O_PATH | O_DIRECTORY | O_CLOEXEC)); @@ -799,6 +820,7 @@ luciole::archive_work::Prepared luciole::archive_work::extract( if (output.close() != 0) { systemError(i18n::tr("operations.archive-reader.could-not-close-extracted-data")); } + work.progress.completedItems.fetch_add(bodyUses.at(path)); } else { reader.skip(); } @@ -828,6 +850,7 @@ luciole::archive_work::Prepared luciole::archive_work::extract( if (::fchmod(folder.get(), static_cast(0700U | (entry.mode & 0055U))) != 0) { systemError(i18n::tr("operations.archive-reader.could-not-set-folder-permissions")); } + work.progress.completedItems.fetch_add(1); } else if (entry.kind == ArchiveEntryKind::File || entry.kind == ArchiveEntryKind::Hardlink) { const auto target = body(path); const auto id = std::to_string(entries.at(target)); @@ -863,6 +886,7 @@ luciole::archive_work::Prepared luciole::archive_work::extract( if (::symlinkat(entry.link.c_str(), parent.get(), entry.name.c_str()) != 0) { systemError(i18n::tr("operations.archive-reader.could-not-create-extracted-link")); } + work.progress.completedItems.fetch_add(1); } } work.check(); diff --git a/src/operations/archive_service.cpp b/src/operations/archive_service.cpp index e96b9acd..98fd83af 100644 --- a/src/operations/archive_service.cpp +++ b/src/operations/archive_service.cpp @@ -244,6 +244,9 @@ struct luciole::ArchiveService::State : std::enable_shared_from_this { results.clear(); progress.bytes.store(0); progress.items.store(0); + progress.totalBytes.store(0); + progress.totalItems.store(0); + progress.completedItems.store(0); cancel = CancelToken{}; if (!known) { known = catalog; @@ -275,6 +278,9 @@ struct luciole::ArchiveService::State : std::enable_shared_from_this { const auto destination = task.destination; progress.bytes.store(0); progress.items.store(0); + progress.totalBytes.store(0); + progress.totalItems.store(0); + progress.completedItems.store(0); progress.passwordNeeded.store(false); progress.passwordFormat = ArchiveFormat::Zip; phase = operation == Operation::Inspect ? ArchivePhase::Reading @@ -467,6 +473,15 @@ std::uint64_t luciole::ArchiveService::bytes() const { std::size_t luciole::ArchiveService::items() const { return m_batch ? m_batch->worker->items() : m_state->progress.items.load(); } +std::uint64_t luciole::ArchiveService::totalBytes() const { + return m_batch ? m_batch->worker->totalBytes() : m_state->progress.totalBytes.load(); +} +std::size_t luciole::ArchiveService::totalItems() const { + return m_batch ? m_batch->worker->totalItems() : m_state->progress.totalItems.load(); +} +std::size_t luciole::ArchiveService::completedItems() const { + return m_batch ? m_batch->worker->completedItems() : m_state->progress.completedItems.load(); +} const std::optional& luciole::ArchiveService::error() const { return !m_state->error && m_batch && !m_batch->running ? m_batch->error : m_state->error; } diff --git a/src/operations/archive_service.h b/src/operations/archive_service.h index c1e0f4b5..5fe3cd82 100644 --- a/src/operations/archive_service.h +++ b/src/operations/archive_service.h @@ -109,6 +109,10 @@ namespace luciole { TransferFlush flushPhase() const; std::uint64_t bytes() const; std::size_t items() const; + // Measured denominators of the running job; 0 = unknown. + std::uint64_t totalBytes() const; + std::size_t totalItems() const; + std::size_t completedItems() const; const std::optional& error() const; const std::shared_ptr& catalog() const; std::optional takeOpenedMember(); diff --git a/src/operations/archive_work.h b/src/operations/archive_work.h index e4e8cf29..beb7f02b 100644 --- a/src/operations/archive_work.h +++ b/src/operations/archive_work.h @@ -11,6 +11,9 @@ namespace luciole::archive_work { struct Progress { std::atomic bytes{0}; std::atomic items{0}; + std::atomic totalBytes{0}; + std::atomic totalItems{0}; + std::atomic completedItems{0}; std::atomic passwordNeeded{false}; // Accessed by a worker, then its completion callback, never concurrently. std::string sourceStamp; diff --git a/src/operations/archive_writer.cpp b/src/operations/archive_writer.cpp index d91275a5..9eb7a57f 100644 --- a/src/operations/archive_writer.cpp +++ b/src/operations/archive_writer.cpp @@ -6,10 +6,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include @@ -307,6 +309,35 @@ namespace { throwFileError(FileErrorKind::Changed, i18n::tr("operations.archive-writer.archive-source-was-replaced")); } } + void measureItem( + int parent, const std::string& name, Work& work, std::uint64_t& bytes, std::size_t& count, bool& known, + unsigned depth + ) { + work.check(); + if (depth > work.limits.maxDepth || count >= work.limits.maxEntries) { + known = false; + return; + } + ++count; + const auto info = statAt(parent, name); + if (S_ISDIR(info.st_mode)) { + const auto folder = opened(::openat(parent, name.c_str(), O_RDONLY | O_DIRECTORY | O_NOFOLLOW | O_CLOEXEC)); + forEachChild(folder.get(), work, [&](const std::string& child) { + if (known) { + measureItem(folder.get(), child, work, bytes, count, known, depth + 1); + } + }); + } else if (S_ISREG(info.st_mode)) { + if (info.st_size < 0 + || static_cast(info.st_size) > std::numeric_limits::max() - bytes) { + known = false; + return; + } + bytes += static_cast(info.st_size); + } else if (!S_ISLNK(info.st_mode)) { + known = false; + } + } } // namespace bool luciole::archiveEncryptionAvailable() { @@ -393,6 +424,21 @@ luciole::archive_work::Prepared luciole::archive_work::compress( (void)parent; Stage stage; const auto output = fs::path(stage.path) / name; + std::uint64_t totalBytes = 0; + std::size_t totalItems = 0; + bool totalsKnown = true; + for (const auto& source : sources) { + if (!totalsKnown) { + break; + } + const fs::path path(native(source)); + const auto inputParent = opened(::open(path.parent_path().c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC)); + measureItem(inputParent.get(), path.filename().native(), work, totalBytes, totalItems, totalsKnown, 0); + } + if (totalsKnown) { + progress.totalBytes.store(totalBytes); + progress.totalItems.store(totalItems); + } Writer writer(output.native(), *descriptor, level, work, passwords); std::set names; for (const auto& source : sources) { diff --git a/tests/archive_service_test.cpp b/tests/archive_service_test.cpp index 09c9a4e5..55f3aad4 100644 --- a/tests/archive_service_test.cpp +++ b/tests/archive_service_test.cpp @@ -125,6 +125,86 @@ namespace { void wait(luciole::ArchiveService& service, Pump& pump) { pump.until([&] { return !service.busy(); }); } + luciole::ArchivePasswordRequest passwordRequest(luciole::ArchiveService& service, Pump& pump); + std::string fixtureBytes(const auto& fixture); + void testMeasuredTotals(const Fixture& fixture, Pump& pump) { + const auto src = fixture.root / "measured-src"; + fs::create_directories(src / "inner"); + write(src / "one.txt", std::string(1000, 'a')); + write(src / "inner/two.txt", std::string(500, 'b')); + fs::create_symlink("one.txt", src / "link"); + luciole::ArchiveService service; + const auto archive = fixture.root / "measured.zip"; + TEST_CHECK(service.compress({location(src)}, location(archive), luciole::ArchiveFormat::Zip)); + pump.until([&] { return service.totalBytes() > 0; }); + TEST_CHECK(service.totalBytes() == 1500 && service.totalItems() == 5); + wait(service, pump); + TEST_CHECK(!service.error() && service.bytes() == 1500 && service.items() == 5); + const auto dest = fixture.root / "measured-dest"; + TEST_CHECK(service.extract(location(archive), location(dest))); + pump.until([&] { return service.totalBytes() > 0; }); + TEST_CHECK(service.totalBytes() == 1500 && service.totalItems() == 5); + wait(service, pump); + TEST_CHECK(!service.error() && service.bytes() == 1500 && service.completedItems() == service.totalItems()); + // A selection narrows the denominators to the selected entries and their bytes. + const auto selected = fixture.root / "measured-sel"; + TEST_CHECK(service.extract(location(archive), location(selected), {"measured-src/one.txt"})); + pump.until([&] { return service.totalBytes() > 0; }); + TEST_CHECK(service.totalBytes() == 1000 && service.totalItems() == 1); + wait(service, pump); + TEST_CHECK(!service.error() && service.completedItems() == 1); + // Hard-link aliases share one body; each alias counts once that body is extracted. + const auto links = fixture.root / "links.tar"; + tar(links, + {{"dir/real", "linked data", {}, AE_IFREG, 04777}, + {"alias", {}, "dir/real", AE_IFREG}, + {"safe", {}, "dir/../dir/real", AE_IFLNK}}); + const auto linkDest = fixture.root / "measured-links"; + TEST_CHECK(service.extract(location(links), location(linkDest))); + pump.until([&] { return service.totalItems() > 0; }); + TEST_CHECK(service.totalItems() == 4 && service.totalBytes() == 11); + wait(service, pump); + TEST_CHECK(!service.error() && service.completedItems() == 4); + // A single compressed file has no size until decoded, so its byte total stays unknown. + const auto gz = fixture.root / "dump.SQL.gz"; + { + const std::unique_ptr writer( + archive_write_new(), &archive_write_free + ); + TEST_CHECK(archive_write_add_filter(writer.get(), ARCHIVE_FILTER_GZIP) == ARCHIVE_OK); + TEST_CHECK(archive_write_set_format_raw(writer.get()) == ARCHIVE_OK); + TEST_CHECK(archive_write_open_filename(writer.get(), gz.c_str()) == ARCHIVE_OK); + const std::unique_ptr entry( + archive_entry_new(), &archive_entry_free + ); + archive_entry_set_filetype(entry.get(), AE_IFREG); + TEST_CHECK(archive_write_header(writer.get(), entry.get()) == ARCHIVE_OK); + TEST_CHECK(archive_write_data(writer.get(), "select 1;", 9) == 9); + } + const auto single = fixture.root / "measured-single"; + TEST_CHECK(service.extract(location(gz), location(single))); + wait(service, pump); + TEST_CHECK(!service.error() && read(single / "dump.SQL") == "select 1;"); + TEST_CHECK(service.totalBytes() == 0 && service.totalItems() == 1); + // Provider-run unpacking (encrypted 7z) credits only when its child process ends, so the + // denominators stay withheld and the row keeps its spinner instead of a stuck bar. + if (const auto* const encrypted = + std::ranges::find(sevenzip_fixtures::archives, true, &sevenzip_fixtures::Fixture::encrypted); + encrypted != sevenzip_fixtures::archives.end()) { + const auto path = fixture.root / "metered.7z"; + write(path, fixtureBytes(*encrypted)); + luciole::ArchiveService metered; + TEST_CHECK(metered.inspect(location(path))); + wait(metered, pump); + const auto known = metered.catalog(); + TEST_CHECK(metered.extract(location(path), location(fixture.root / "metered-7z"), {}, known)); + const auto request = passwordRequest(metered, pump); + TEST_CHECK(metered.providePassword(request.id, "fixture-pass")); + wait(metered, pump); + TEST_CHECK(!metered.error()); + TEST_CHECK(metered.totalBytes() == 0 && metered.totalItems() == 0); + } + } void testExtractionStorage(const Fixture& fixture, Pump& pump) { const auto source = fixture.root / "storage.zip"; const auto parent = fixture.root / "outputs"; @@ -2966,6 +3046,7 @@ int main(int argc, char** argv) { testXzMemberFromLargeArchive(fixture, pump); testCompressedTarProviders(fixture, pump); testCompressedFile(fixture, pump); + testMeasuredTotals(fixture, pump); testCompressedTarFailures(fixture, pump); testCompressedPaddingLimit(fixture, pump); testRoundTrips(fixture, pump); diff --git a/tests/operation_activity_test.cpp b/tests/operation_activity_test.cpp index dca0bd6b..35c0c4b4 100644 --- a/tests/operation_activity_test.cpp +++ b/tests/operation_activity_test.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -1235,7 +1236,7 @@ namespace { {{fixture.at("success"), fixture.at("missing")}, fixture.at("destination"), luciole::TransferAction::Copy} )); auto live = workspace.hub.activities(); - TEST_CHECK(live.size() == 1 && !live[0].finished && live[0].canCancel); + TEST_CHECK(live.size() == 1 && !live[0].finished && live[0].canCancel && !live[0].progress); pump.until([&] { return service.conflict().has_value(); }); const auto destination = fixture.root / "destination"; const auto held = fixture.root / "held-destination"; @@ -1502,6 +1503,59 @@ namespace { const auto results = workspace.hub.activities(); TEST_CHECK(results.size() == 1 && results[0].finished && results[0].state == ActivityState::Cancelled); } + void meteredArchiveActivity(Pump& pump) { + Fixture fixture; + { + std::ofstream out(fixture.root / "bulk.bin", std::ios::binary); + const std::string block(1 << 20, 'B'); + for (int i = 0; i < 128; ++i) { + out << block; + } + } + luciole::ArchiveService writer; + TEST_CHECK(writer.compress({fixture.at("bulk.bin")}, fixture.at("bulk.tar"), luciole::ArchiveFormat::Tar)); + pump.until([&] { return !writer.busy(); }); + TEST_CHECK(!writer.error()); + Workspace workspace; + auto job = workspace.hub.create(workspace.page); + auto& archive = job->service(); + TEST_CHECK(archive.extract(fixture.at("bulk.tar"), fixture.at("out"))); + pump.until([&] { return archive.totalBytes() > 0; }); // The denominator lands before payload is written. + std::optional live; + pump.until([&] { + const auto activities = workspace.hub.activities(); + if (!activities.empty() && activities.front().progress) { + live = activities.front(); + return true; + } + return !archive.busy(); + }); + TEST_CHECK(live && live->progress >= 0.0F && live->progress <= 1.0F); + TEST_CHECK(live && !live->progressText.empty() && live->detailLeft.contains(" of ")); + TEST_CHECK(live && live->statusRight.contains("Extracting")); + pump.until([&] { return !archive.busy(); }); + TEST_CHECK(!archive.error() && fs::exists(fixture.root / "out/bulk.bin")); + auto batchJob = workspace.hub.create(workspace.page); + auto& batch = batchJob->service(); + fs::create_directory(fixture.root / "batch-out"); + TEST_CHECK(batch.extractMany({fixture.at("bulk.tar")}, fixture.at("batch-out"))); + std::optional batchMid; + pump.until([&] { + if (batch.totalBytes() > 0) { + for (const auto& activity : workspace.hub.activities()) { + if (activity.id == batchJob->id()) { + batchMid = activity; + } + } + return true; + } + return !batch.busy(); + }); + // A batch row keeps the per-archive fraction even while its running child publishes byte meters. + TEST_CHECK(batchMid && batchMid->detailLeft.empty() && batchMid->statusRight.empty() && batchMid->progress); + pump.until([&] { return !batch.busy(); }); + TEST_CHECK(!batch.error() && fs::exists(fixture.root / "batch-out/bulk/bulk.bin")); + } void cancelledPacedTransferCleanup(Pump& pump) { Fixture fixture; { @@ -1609,6 +1663,7 @@ int main(int argc, char** argv) { conflictCancelAndRehome(pump); historyAndInspection(pump); cancelledArchive(pump); + meteredArchiveActivity(pump); batchArchiveActivity(pump); preparedJobCompletion(pump); boundedReports(pump); From 822326f04b9ffde732888b6653e3c4ea0e817fe6 Mon Sep 17 00:00:00 2001 From: t <294862818+tcz0g@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:53:50 +0100 Subject: [PATCH 2/2] test(archives): gate measured-total polling on both denominator stores --- tests/archive_service_test.cpp | 6 +++--- tests/operation_activity_test.cpp | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/archive_service_test.cpp b/tests/archive_service_test.cpp index 55f3aad4..5925fb1c 100644 --- a/tests/archive_service_test.cpp +++ b/tests/archive_service_test.cpp @@ -136,20 +136,20 @@ namespace { luciole::ArchiveService service; const auto archive = fixture.root / "measured.zip"; TEST_CHECK(service.compress({location(src)}, location(archive), luciole::ArchiveFormat::Zip)); - pump.until([&] { return service.totalBytes() > 0; }); + pump.until([&] { return service.totalBytes() > 0 && service.totalItems() > 0; }); TEST_CHECK(service.totalBytes() == 1500 && service.totalItems() == 5); wait(service, pump); TEST_CHECK(!service.error() && service.bytes() == 1500 && service.items() == 5); const auto dest = fixture.root / "measured-dest"; TEST_CHECK(service.extract(location(archive), location(dest))); - pump.until([&] { return service.totalBytes() > 0; }); + pump.until([&] { return service.totalBytes() > 0 && service.totalItems() > 0; }); TEST_CHECK(service.totalBytes() == 1500 && service.totalItems() == 5); wait(service, pump); TEST_CHECK(!service.error() && service.bytes() == 1500 && service.completedItems() == service.totalItems()); // A selection narrows the denominators to the selected entries and their bytes. const auto selected = fixture.root / "measured-sel"; TEST_CHECK(service.extract(location(archive), location(selected), {"measured-src/one.txt"})); - pump.until([&] { return service.totalBytes() > 0; }); + pump.until([&] { return service.totalBytes() > 0 && service.totalItems() > 0; }); TEST_CHECK(service.totalBytes() == 1000 && service.totalItems() == 1); wait(service, pump); TEST_CHECK(!service.error() && service.completedItems() == 1); diff --git a/tests/operation_activity_test.cpp b/tests/operation_activity_test.cpp index 35c0c4b4..e769e61e 100644 --- a/tests/operation_activity_test.cpp +++ b/tests/operation_activity_test.cpp @@ -1520,7 +1520,9 @@ namespace { auto job = workspace.hub.create(workspace.page); auto& archive = job->service(); TEST_CHECK(archive.extract(fixture.at("bulk.tar"), fixture.at("out"))); - pump.until([&] { return archive.totalBytes() > 0; }); // The denominator lands before payload is written. + pump.until([&] { + return archive.totalBytes() > 0 && archive.totalItems() > 0; + }); // Both denominators land before payload is written. std::optional live; pump.until([&] { const auto activities = workspace.hub.activities();