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
Address suggestions by danmoseley
  • Loading branch information
carlossanlop committed Aug 22, 2022
commit 5da8dd98c203d10935503be75a4d9bf9737f61e7
Original file line number Diff line number Diff line change
Expand Up @@ -366,10 +366,10 @@ private static IEnumerable<FileSystemInfo> GetFileSystemEnumerationForCreation(s
RecurseSubdirectories = true
})
{
ShouldRecursePredicate = IsDirectorySymlink
ShouldRecursePredicate = IsNotADirectorySymlink
};

static bool IsDirectorySymlink(ref FileSystemEntry entry) => entry.IsDirectory && (entry.Attributes & FileAttributes.ReparsePoint) == 0;
static bool IsNotADirectorySymlink(ref FileSystemEntry entry) => entry.IsDirectory && (entry.Attributes & FileAttributes.ReparsePoint) == 0;
}

// Determines what should be the base path for all the entries when creating an archive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,14 @@ public void SkipRecursionIntoDirectorySymlinks()
TarFile.CreateFromDirectory(sourceDirectoryName, destinationArchive, includeBaseDirectory: false);

using FileStream archiveStream = File.OpenRead(destinationArchive);
using (TarReader reader = new(archiveStream, leaveOpen: false))
{
TarEntry entry = reader.GetNextEntry();
Assert.NotNull(entry);
Assert.Equal("subDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);
using TarReader reader = new(archiveStream, leaveOpen: false);

Assert.Null(reader.GetNextEntry()); // file.txt should not be found
}
TarEntry entry = reader.GetNextEntry();
Assert.NotNull(entry);
Assert.Equal("subDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);

Assert.Null(reader.GetNextEntry()); // file.txt should not be found
}

[Fact]
Expand All @@ -245,15 +244,14 @@ public void SkipRecursionIntoBaseDirectorySymlink()
TarFile.CreateFromDirectory(sourceDirectoryName, destinationArchive, includeBaseDirectory: true); // Base directory is a symlink, do not recurse

using FileStream archiveStream = File.OpenRead(destinationArchive);
using (TarReader reader = new(archiveStream, leaveOpen: false))
{
TarEntry entry = reader.GetNextEntry();
Assert.NotNull(entry);
Assert.Equal("baseDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);
using TarReader reader = new(archiveStream, leaveOpen: false);

Assert.Null(reader.GetNextEntry());
}
TarEntry entry = reader.GetNextEntry();
Assert.NotNull(entry);
Assert.Equal("baseDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);

Assert.Null(reader.GetNextEntry());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,14 @@ public async Task SkipRecursionIntoDirectorySymlinksAsync()
await TarFile.CreateFromDirectoryAsync(sourceDirectoryName, destinationArchive, includeBaseDirectory: false);

await using FileStream archiveStream = File.OpenRead(destinationArchive);
await using (TarReader reader = new(archiveStream, leaveOpen: false))
{
TarEntry entry = await reader.GetNextEntryAsync();
Assert.NotNull(entry);
Assert.Equal("subDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);
await using TarReader reader = new(archiveStream, leaveOpen: false);

Assert.Null(await reader.GetNextEntryAsync()); // file.txt should not be found
}
TarEntry entry = await reader.GetNextEntryAsync();
Assert.NotNull(entry);
Assert.Equal("subDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);

Assert.Null(await reader.GetNextEntryAsync()); // file.txt should not be found
}

[Fact]
Expand All @@ -289,15 +288,14 @@ public async Task SkipRecursionIntoBaseDirectorySymlinkAsync()
await TarFile.CreateFromDirectoryAsync(sourceDirectoryName, destinationArchive, includeBaseDirectory: true); // Base directory is a symlink, do not recurse

await using FileStream archiveStream = File.OpenRead(destinationArchive);
await using (TarReader reader = new(archiveStream, leaveOpen: false))
{
TarEntry entry = await reader.GetNextEntryAsync();
Assert.NotNull(entry);
Assert.Equal("baseDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);
await using TarReader reader = new(archiveStream, leaveOpen: false);

Assert.Null(await reader.GetNextEntryAsync()); // subDirectory should not be found
}
TarEntry entry = await reader.GetNextEntryAsync();
Assert.NotNull(entry);
Assert.Equal("baseDirectory/", entry.Name);
Assert.Equal(TarEntryType.SymbolicLink, entry.EntryType);

Assert.Null(await reader.GetNextEntryAsync()); // subDirectory should not be found
}
}
}