Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Changes following code review
Renamed Dirty and DirtyState to Changed and ChangeState.
Explicitly assigned Unchanged as a zero-value ChangeState.
  • Loading branch information
edwardneal committed Jun 25, 2024
commit 03f7fcdbbb666fdce505e05916f35331c88cfcca
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public ZipArchive(Stream stream, ZipArchiveMode mode, bool leaveOpen, Encoding?
_entries = new List<ZipArchiveEntry>();
_entriesCollection = new ReadOnlyCollection<ZipArchiveEntry>(_entries);
_entriesDictionary = new Dictionary<string, ZipArchiveEntry>();
Dirty = 0;
Changed = ChangeState.Unchanged;
_readEntries = false;
_leaveOpen = leaveOpen;
_centralDirectoryStart = 0; // invalid until ReadCentralDirectory
Expand Down Expand Up @@ -228,7 +228,7 @@ public string Comment
set
{
_archiveComment = ZipHelper.GetEncodedTruncatedBytesFromString(value, EntryNameAndCommentEncoding, ZipEndOfCentralDirectoryBlock.ZipFileCommentMaxLength, out _);
Dirty |= DirtyState.DynamicLengthMetadata;
Changed |= ChangeState.DynamicLengthMetadata;
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ private set

// This property's value only relates to the top-level fields of the archive (such as the archive comment.)
// New entries in the archive won't change its state.
internal DirtyState Dirty { get; private set; }
internal ChangeState Changed { get; private set; }

private ZipArchiveEntry DoCreateEntry(string entryName, CompressionLevel? compressionLevel)
{
Expand Down Expand Up @@ -670,7 +670,7 @@ private void WriteFile()
{
if (entry._originallyInArchive)
{
if (entry.Dirty == 0)
if (entry.Changed == ChangeState.Unchanged)
{
// Keep track of the expected position of the file entry after the final untouched file entry so that when the loop completes,
// we'll know which position to start writing new entries from.
Expand All @@ -688,7 +688,7 @@ private void WriteFile()
{
// If the pending data to write is fixed-length metadata in the header, there's no need to load the full file for
// inflation and deflation.
if ((entry.Dirty & (DirtyState.DynamicLengthMetadata | DirtyState.StoredData)) != 0)
if ((entry.Changed & (ChangeState.DynamicLengthMetadata | ChangeState.StoredData)) != 0)
{
dynamicDirtyStartingOffset = Math.Min(dynamicDirtyStartingOffset, entry._offsetOfLocalHeader);
}
Expand Down Expand Up @@ -781,7 +781,7 @@ private void WriteArchiveEpilogue(long startOfCentralDirectory, long sizeOfCentr
}

// write normal eocd
if (centralDirectoryChanged | (Dirty != 0))
if (centralDirectoryChanged | (Changed != ChangeState.Unchanged))
{
ZipEndOfCentralDirectoryBlock.WriteBlock(_archiveStream, _entries.Count, startOfCentralDirectory, sizeOfCentralDirectory, _archiveComment);
}
Expand All @@ -792,8 +792,9 @@ private void WriteArchiveEpilogue(long startOfCentralDirectory, long sizeOfCentr
}

[Flags]
internal enum DirtyState
internal enum ChangeState
{
Unchanged = 0x0,
FixedLengthMetadata = 0x1,
DynamicLengthMetadata = 0x2,
StoredData = 0x4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ internal ZipArchiveEntry(ZipArchive archive, ZipCentralDirectoryFileHeader cd)

_compressionLevel = MapCompressionLevel(_generalPurposeBitFlag, CompressionMethod);

Dirty = 0;
Changed = ZipArchive.ChangeState.Unchanged;
}

// Initializes a ZipArchiveEntry instance for a new archive entry with a specified compression level.
Expand Down Expand Up @@ -151,7 +151,7 @@ internal ZipArchiveEntry(ZipArchive archive, string entryName)
_archive.AcquireArchiveStream(this);
}

Dirty = 0;
Changed = ZipArchive.ChangeState.Unchanged;
}

/// <summary>
Expand Down Expand Up @@ -191,7 +191,7 @@ public int ExternalAttributes
{
ThrowIfInvalidArchive();
_externalFileAttr = (uint)value;
Dirty |= ZipArchive.DirtyState.FixedLengthMetadata;
Changed |= ZipArchive.ChangeState.FixedLengthMetadata;
}
}

Expand All @@ -214,7 +214,7 @@ public string Comment
{
_generalPurposeBitFlag |= BitFlagValues.UnicodeFileNameAndComment;
}
Dirty |= ZipArchive.DirtyState.DynamicLengthMetadata;
Changed |= ZipArchive.ChangeState.DynamicLengthMetadata;
}
}

Expand Down Expand Up @@ -279,7 +279,7 @@ public DateTimeOffset LastWriteTime
throw new ArgumentOutOfRangeException(nameof(value), SR.DateTimeOutOfRange);

_lastModified = value;
Dirty |= ZipArchive.DirtyState.FixedLengthMetadata;
Changed |= ZipArchive.ChangeState.FixedLengthMetadata;
}
}

Expand All @@ -302,7 +302,7 @@ public long Length
/// </summary>
public string Name => ParseFileName(FullName, _versionMadeByPlatform);

internal ZipArchive.DirtyState Dirty { get; private set; }
internal ZipArchive.ChangeState Changed { get; private set; }

/// <summary>
/// Deletes the entry from the archive.
Expand Down Expand Up @@ -533,7 +533,7 @@ internal void WriteCentralDirectoryFileHeader(bool forceWrite)
extraFieldLength = (ushort)bigExtraFieldLength;
}

if (_originallyInArchive && Dirty == 0 && !forceWrite)
if (_originallyInArchive && Changed == ZipArchive.ChangeState.Unchanged && !forceWrite)
{
long centralDirectoryHeaderLength = 46
+ _storedEntryNameBytes.Length
Expand Down Expand Up @@ -716,7 +716,7 @@ private WrappedStream OpenInWriteMode()
_archive.DebugAssertIsStillArchiveStreamOwner(this);

_everOpenedForWrite = true;
Dirty |= ZipArchive.DirtyState.StoredData;
Changed |= ZipArchive.ChangeState.StoredData;
CheckSumAndSizeWriteStream crcSizeStream = GetDataCompressor(_archive.ArchiveStream, true, (object? o, EventArgs e) =>
{
// release the archive stream
Expand All @@ -737,7 +737,7 @@ private WrappedStream OpenInUpdateMode()
ThrowIfNotOpenable(needToUncompress: true, needToLoadIntoMemory: true);

_everOpenedForWrite = true;
Dirty |= ZipArchive.DirtyState.StoredData;
Changed |= ZipArchive.ChangeState.StoredData;
_currentlyOpenForWrite = true;
// always put it at the beginning for them
UncompressedData.Seek(0, SeekOrigin.Begin);
Expand Down Expand Up @@ -946,7 +946,7 @@ private bool WriteLocalFileHeader(bool isEmptyFile, bool forceWrite)

// If this is an existing, unchanged entry then silently skip forwards.
// If it's new or changed, write the header.
if (_originallyInArchive && Dirty == 0 && !forceWrite)
if (_originallyInArchive && Changed == ZipArchive.ChangeState.Unchanged && !forceWrite)
{
writer.Seek(30 + _storedEntryNameBytes.Length, SeekOrigin.Current);

Expand Down