Skip to content

Commit

Permalink
Merge pull request #569 from BrendanGrant/improve_how_missing_parts_a…
Browse files Browse the repository at this point in the history
…re_handled

Improve how missing parts are handled
  • Loading branch information
adamhathcock committed Feb 14, 2021
2 parents 2dd17e3 + 5b86c40 commit 6f08bb7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/SharpCompress/Archives/Rar/RarArchive.cs
Expand Up @@ -10,7 +10,8 @@

namespace SharpCompress.Archives.Rar
{
public class RarArchive : AbstractArchive<RarArchiveEntry, RarVolume>
public class
RarArchive : AbstractArchive<RarArchiveEntry, RarVolume>
{
internal Lazy<IRarUnpack> UnpackV2017 { get; } = new Lazy<IRarUnpack>(() => new SharpCompress.Compressors.Rar.UnpackV2017.Unpack());
internal Lazy<IRarUnpack> UnpackV1 { get; } = new Lazy<IRarUnpack>(() => new SharpCompress.Compressors.Rar.UnpackV1.Unpack());
Expand Down Expand Up @@ -42,7 +43,7 @@ internal RarArchive(IEnumerable<Stream> streams, ReaderOptions options)

protected override IEnumerable<RarArchiveEntry> LoadEntries(IEnumerable<RarVolume> volumes)
{
return RarArchiveEntryFactory.GetEntries(this, volumes);
return RarArchiveEntryFactory.GetEntries(this, volumes, ReaderOptions);
}

protected override IEnumerable<RarVolume> LoadVolumes(IEnumerable<Stream> streams)
Expand Down
9 changes: 6 additions & 3 deletions src/SharpCompress/Archives/Rar/RarArchiveEntry.cs
Expand Up @@ -6,18 +6,21 @@
using SharpCompress.Common.Rar;
using SharpCompress.Common.Rar.Headers;
using SharpCompress.Compressors.Rar;
using SharpCompress.Readers;

namespace SharpCompress.Archives.Rar
{
public class RarArchiveEntry : RarEntry, IArchiveEntry
{
private readonly ICollection<RarFilePart> parts;
private readonly RarArchive archive;
private readonly ReaderOptions readerOptions;

internal RarArchiveEntry(RarArchive archive, IEnumerable<RarFilePart> parts)
internal RarArchiveEntry(RarArchive archive, IEnumerable<RarFilePart> parts, ReaderOptions readerOptions)
{
this.parts = parts.ToList();
this.archive = archive;
this.readerOptions = readerOptions;
}

public override CompressionType CompressionType => CompressionType.Rar;
Expand Down Expand Up @@ -69,13 +72,13 @@ public bool IsComplete
{
get
{
return parts.Select(fp => fp.FileHeader).Any(fh => !fh.IsSplitAfter);
return parts.Select(fp => fp.FileHeader).Any(fh => !fh.IsSplitBefore && !fh.IsSplitAfter);
}
}

private void CheckIncomplete()
{
if (!IsComplete)
if (!readerOptions.DisableCheckIncomplete && !IsComplete)
{
throw new IncompleteArchiveException("ArchiveEntry is incomplete and cannot perform this operation.");
}
Expand Down
6 changes: 4 additions & 2 deletions src/SharpCompress/Archives/Rar/RarArchiveEntryFactory.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using SharpCompress.Common.Rar;
using SharpCompress.Readers;

namespace SharpCompress.Archives.Rar
{
Expand Down Expand Up @@ -36,11 +37,12 @@ private static IEnumerable<IEnumerable<RarFilePart>> GetMatchedFileParts(IEnumer
}

internal static IEnumerable<RarArchiveEntry> GetEntries(RarArchive archive,
IEnumerable<RarVolume> rarParts)
IEnumerable<RarVolume> rarParts,
ReaderOptions readerOptions)
{
foreach (var groupedParts in GetMatchedFileParts(rarParts))
{
yield return new RarArchiveEntry(archive, groupedParts);
yield return new RarArchiveEntry(archive, groupedParts, readerOptions);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/SharpCompress/Common/Rar/Headers/FileHeader.cs
Expand Up @@ -437,6 +437,7 @@ internal uint FileCrc
internal long DataStartPosition { get; set; }
public Stream PackedStream { get; set; }

public bool IsSplitBefore => IsRar5 ? HasHeaderFlag(HeaderFlagsV5.SPLIT_BEFORE) : HasFlag(FileFlagsV4.SPLIT_BEFORE);
public bool IsSplitAfter => IsRar5 ? HasHeaderFlag(HeaderFlagsV5.SPLIT_AFTER) : HasFlag(FileFlagsV4.SPLIT_AFTER);

public bool IsDirectory => HasFlag(IsRar5 ? FileFlagsV5.DIRECTORY : FileFlagsV4.DIRECTORY);
Expand Down
2 changes: 2 additions & 0 deletions src/SharpCompress/Readers/ReaderOptions.cs
Expand Up @@ -10,5 +10,7 @@ public class ReaderOptions : OptionsBase
public bool LookForHeader { get; set; }

public string? Password { get; set; }

public bool DisableCheckIncomplete { get; set; }
}
}

0 comments on commit 6f08bb7

Please sign in to comment.