Skip to content

Commit

Permalink
Fix extending FAT for DirectoryEntries
Browse files Browse the repository at this point in the history
Fixes: #207
  • Loading branch information
jeremy-visionaid committed Nov 16, 2024
1 parent 6f37b70 commit 05070ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
15 changes: 15 additions & 0 deletions OpenMcdf.Tests/StreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,21 @@ public void WriteMultiple(Version version, int length)
}
}

[TestMethod]
[DataRow(Version.V3, 32)]
[DataRow(Version.V4, 256)]
public void CreateMultipleStreams(Version version, int streamCount)
{
using var rootStorage = RootStorage.CreateInMemory(version);
for (int i = 0; i < streamCount; i++)
{
Assert.AreEqual(i, rootStorage.EnumerateEntries().Count());

string streamName = $"TestStream{i}";
using Stream stream = rootStorage.CreateStream(streamName);
}
}

[TestMethod]
[DataRow(Version.V3, 0)]
[DataRow(Version.V3, 63)]
Expand Down
4 changes: 0 additions & 4 deletions OpenMcdf/Fat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ public uint Add(FatEnumerator fatEnumerator, uint startIndex)
&& fatEnumerator.MoveNextFreeEntry();
if (!movedToFreeEntry)
{
Flush();

uint newSectorId = fatSectorEnumerator.Add();

// Next id must be free
Expand All @@ -133,8 +131,6 @@ public uint Add(FatEnumerator fatEnumerator, uint startIndex)

ok = fatEnumerator.MoveNextFreeEntry();
Debug.Assert(ok);

CacheCurrentSector();
}

FatEntry entry = fatEnumerator.Current;
Expand Down
9 changes: 4 additions & 5 deletions OpenMcdf/FatChainEnumerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ public long GetLength()
/// Extends the chain by one
/// </summary>
/// <returns>The ID of the new sector</returns>
public uint Extend()
{
return ExtendFrom(0);
}
public uint Extend() => ExtendFrom(0);

/// <summary>
/// Returns the ID of the first sector in the chain.
Expand Down Expand Up @@ -177,13 +174,15 @@ public uint ExtendFrom(uint hintId)
return startId;
}

Reset();

uint lastId = startId;
while (MoveNext())
{
lastId = current;
}

uint id = fat.Add(fatEnumerator, lastId);
uint id = fat.Add(fatEnumerator, hintId);
fat[lastId] = id;
return id;
}
Expand Down

0 comments on commit 05070ce

Please sign in to comment.