Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
54 changes: 50 additions & 4 deletions src/Zio.Tests/FileSystems/TestZipArchiveFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ public void TestOpenStreamsMultithreaded()


[Theory]
[InlineData("TestData/Linux.zip")]
[InlineData("TestData/Windows.zip")]
[InlineData("TestData/OsZips/Linux.zip")]
[InlineData("TestData/OsZips/Windows.zip")]
public void TestCaseInSensitiveZip(string path)
{
using var stream = File.OpenRead(path);
Expand All @@ -253,8 +253,8 @@ public void TestCaseInSensitiveZip(string path)
}

[Theory]
[InlineData("TestData/Linux.zip")]
[InlineData("TestData/Windows.zip")]
[InlineData("TestData/OsZips/Linux.zip")]
[InlineData("TestData/OsZips/Windows.zip")]
public void TestCaseSensitiveZip(string path)
{
using var stream = File.OpenRead(path);
Expand Down Expand Up @@ -329,4 +329,50 @@ public void TestSaveFile()
File.Delete(path);
}
}

[Theory]
[InlineData("TestData/RootFiles/WithoutRootSlash.zip", false)]
[InlineData("TestData/RootFiles/WithRootSlash.zip", true)]
public void TestReadDifferentSlash(string zipPath, bool leadingRootSlash)
{
using var fs = new ZipArchiveFileSystem(zipPath);

Assert.Equal(leadingRootSlash, fs.LeadingSlashInArchive);

Assert.True(fs.FileExists("/Test.txt"));
Assert.Equal("Test", fs.ReadAllText("/Test.txt"));
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void TestWriteDifferentSlash(bool leadingRootSlash)
{
using var memStream = new MemoryStream();

using (var fs = new ZipArchiveFileSystem(memStream, leaveOpen: true))
{
fs.LeadingSlashInArchive = leadingRootSlash;

Assert.Equal(leadingRootSlash, fs.LeadingSlashInArchive);

fs.WriteAllText("/Test.txt", "Test");
}

memStream.Seek(0, SeekOrigin.Begin);

using (var fs = new ZipArchiveFileSystem(memStream, leaveOpen: true))
{
Assert.Equal(leadingRootSlash, fs.LeadingSlashInArchive);

Assert.True(fs.FileExists("/Test.txt"));
Assert.Equal("Test", fs.ReadAllText("/Test.txt"));
}

memStream.Seek(0, SeekOrigin.Begin);

using var zipArchive = new ZipArchive(memStream, ZipArchiveMode.Read);

Assert.Equal(leadingRootSlash, zipArchive.Entries[0].FullName.StartsWith("/"));
}
}
37 changes: 37 additions & 0 deletions src/Zio.Tests/FileSystems/TestZipArchiveFileSystemCompact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,43 @@ public void TestDirectoryExceptions()
#endif
}

[Fact]
public void TestDirectoryDelete()
{
fs.CreateDirectory("/dir");
fs.WriteAllText("/dir/file.txt", "test");

fs.CreateDirectory("/dir2");
fs.WriteAllText("/dir2/file2.txt", "test");

fs.DeleteDirectory("/dir", isRecursive: true);

Assert.False(fs.DirectoryExists("/dir"));

Assert.True(fs.DirectoryExists("/dir2"));
Assert.True(fs.FileExists("/dir2/file2.txt"));
}

[Fact]
public void TestDirectoryMove()
{
fs.CreateDirectory("/dir");
fs.WriteAllText("/dir/file.txt", "test");

fs.CreateDirectory("/dir2");
fs.WriteAllText("/dir2/file2.txt", "test");

fs.MoveDirectory("/dir", "/moved");

Assert.False(fs.DirectoryExists("/dir"));

Assert.True(fs.DirectoryExists("/moved"));
Assert.True(fs.FileExists("/moved/file.txt"));

Assert.True(fs.DirectoryExists("/dir2"));
Assert.True(fs.FileExists("/dir2/file2.txt"));
}

[Fact]
public void TestFile()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Zio.Tests/TestData/OsZips/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
These ZIP files contains the following structure:
Folder/
File.txt [Content: Test]
7 changes: 7 additions & 0 deletions src/Zio.Tests/TestData/RootFiles/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
These ZIP files contain a single file.

In WithRootSlash, the file is contained in the root folder (/Test.txt).
This was the behavior in Zio 0.21.

In WithoutRootSlash, the file is contained directly in the ZIP file (Test.txt).
This is the current behavior.
Binary file added src/Zio.Tests/TestData/RootFiles/WithRootSlash.zip
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions src/Zio.Tests/Zio.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">$(TargetFrameworks);net472</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>10</LangVersion>
</PropertyGroup>
Expand Down
Loading
Loading