mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-07-12 12:07:04 +00:00
Merge pull request #933 from Morilli/zipentry-attribute
Implement `Attrib` for `ZipEntry`
This commit is contained in:
@@ -123,8 +123,6 @@ internal class DirectoryEntryHeader : ZipFileEntry
|
||||
|
||||
public long RelativeOffsetOfEntryHeader { get; set; }
|
||||
|
||||
public uint ExternalFileAttributes { get; set; }
|
||||
|
||||
public ushort InternalFileAttributes { get; set; }
|
||||
|
||||
public ushort DiskNumberStart { get; set; }
|
||||
|
||||
@@ -121,5 +121,7 @@ internal abstract class ZipFileEntry : ZipHeader
|
||||
|
||||
internal bool IsZip64 => CompressedSize >= uint.MaxValue;
|
||||
|
||||
internal uint ExternalFileAttributes { get; set; }
|
||||
|
||||
internal string? Comment { get; set; }
|
||||
}
|
||||
|
||||
@@ -152,6 +152,7 @@ internal sealed class SeekableZipHeaderFactory : ZipHeaderFactory
|
||||
|
||||
// populate fields only known from the DirectoryEntryHeader
|
||||
localEntryHeader.HasData = directoryEntryHeader.HasData;
|
||||
localEntryHeader.ExternalFileAttributes = directoryEntryHeader.ExternalFileAttributes;
|
||||
localEntryHeader.Comment = directoryEntryHeader.Comment;
|
||||
|
||||
if (FlagUtility.HasFlag(localEntryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
|
||||
|
||||
@@ -84,5 +84,7 @@ public class ZipEntry : Entry
|
||||
|
||||
internal override IEnumerable<FilePart> Parts => _filePart.Empty();
|
||||
|
||||
public override int? Attrib => (int?)_filePart?.Header.ExternalFileAttributes;
|
||||
|
||||
public string? Comment => _filePart?.Header.Comment;
|
||||
}
|
||||
|
||||
@@ -832,4 +832,15 @@ public class ZipArchiveTests : ArchiveTests
|
||||
using var _ = firstEntry.OpenEntryStream();
|
||||
Assert.Equal(29, firstEntry.Comment.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Zip_FilePermissions()
|
||||
{
|
||||
using var archive = ArchiveFactory.Open(Path.Combine(TEST_ARCHIVES_PATH, "Zip.644.zip"));
|
||||
|
||||
var firstEntry = archive.Entries.First();
|
||||
const int S_IFREG = 0x8000;
|
||||
const int expected = (S_IFREG | 0b110_100_100) << 16; // 0644 mode regular file
|
||||
Assert.Equal(expected, firstEntry.Attrib);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
tests/TestArchives/Archives/Zip.644.zip
Normal file
BIN
tests/TestArchives/Archives/Zip.644.zip
Normal file
Binary file not shown.
Reference in New Issue
Block a user