Skip to content

Fix SevenZipArchive.IsSolidAsync() always returning false#1284

Merged
adamhathcock merged 2 commits into
releasefrom
copilot/fix-7z-archive-solid-check
Apr 13, 2026
Merged

Fix SevenZipArchive.IsSolidAsync() always returning false#1284
adamhathcock merged 2 commits into
releasefrom
copilot/fix-7z-archive-solid-check

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

IAsyncArchive.IsSolidAsync() always returned false for 7z archives regardless of archive structure, while IArchive.IsSolid returned the correct value.

Root cause

AbstractArchive.Async.cs provides a base implementation that always returns false:

public virtual ValueTask<bool> IsSolidAsync() => new(false);

SevenZipArchive overrides the sync IsSolid property correctly (checking if any compressed folder contains more than one file), but was missing the async counterpart. RarArchive already has its own IsSolidAsync() override.

Changes

  • SevenZipArchive.Async.cs: Added IsSolidAsync() override using async enumeration with the same logic as the sync property. Uses Skip(1).Any() rather than Count() > 1 to short-circuit on the second element:
public override async ValueTask<bool> IsSolidAsync()
{
    var entries = await EntriesAsync
        .Where(x => !x.IsDirectory)
        .ToListAsync()
        .ConfigureAwait(false);
    return entries.GroupBy(x => x.FilePart.Folder).Any(folder => folder.Skip(1).Any());
}
  • SevenZipArchive.cs: Applied the same Skip(1).Any() optimization to the sync IsSolid property.

  • SevenZipArchiveAsyncTests.cs: Added SevenZipArchive_TestSolidDetectionAsync to verify async detection matches sync detection across solid, single-block solid, and non-solid archives. Updated existing async tests to use IsSolidAsync() directly instead of casting to the concrete type to access the sync property.

SevenZipArchive was missing an override for IsSolidAsync(), so the
base class default (always returning false) was used. Added an override
that uses the same logic as the sync IsSolid property: load entries
asynchronously and check if any folder has more than one file.

Also updated existing async tests to use IsSolidAsync() instead of
casting to SevenZipArchive to call the sync IsSolid, and added a new
SevenZipArchive_TestSolidDetectionAsync test that mirrors the existing
sync SevenZipArchive_TestSolidDetection test.

Agent-Logs-Url: https://github.com/adamhathcock/sharpcompress/sessions/60f8daec-e784-4845-a65c-5a493fbb53ef

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix inconsistent solid check between sync and async methods for 7z archive Fix SevenZipArchive.IsSolidAsync() always returning false Apr 13, 2026
Copilot AI requested a review from adamhathcock April 13, 2026 15:33
@adamhathcock adamhathcock marked this pull request as ready for review April 13, 2026 15:38
@adamhathcock adamhathcock merged commit 20932b8 into release Apr 13, 2026
4 checks passed
@adamhathcock adamhathcock deleted the copilot/fix-7z-archive-solid-check branch April 13, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]Determine a 7z archive is solid,sync method and async method return different result.

2 participants