Skip to content

feat(fastzip): allow custom filesystemscanner#678

Open
piksel wants to merge 1 commit intomasterfrom
feat/custom-filesystemscanner
Open

feat(fastzip): allow custom filesystemscanner#678
piksel wants to merge 1 commit intomasterfrom
feat/custom-filesystemscanner

Conversation

@piksel
Copy link
Copy Markdown
Member

@piksel piksel commented Oct 22, 2021

Fixes #676

Or rather, allows it to be handled with a derived class:

  new FastZip().CreateZip(outStream, srcDir, recurse: true, new CustomFileSystemScanner(filter), leaveOpen: true);
class CustomFileSystemScanner:  FileSystemScanner 
{
	static IEnumerable<string> FixupNet5Enumeration(IEnumerable<string> items)
		=> items
			.Select(t => t.TrimEnd('\0'))
			.Where(t => {
				var itemName = Path.GetFileName(t);
				return itemName != "." && itemName != "..";
			});

	protected override IEnumerable<string> GetDirectories(string directory) 
		=> FixupNet5Enumeration(base.GetDirectories(directory));

	protected override IEnumerable<string> GetFiles(string directory) 
		=> FixupNet5Enumeration(base.GetFiles(directory));

	public CustomFileSystemScanner(string ff): base(ff) {}
	public CustomFileSystemScanner(string ff, string df): base(ff, df) {}
	public CustomFileSystemScanner(IScanFilter ff): base(ff){}
	public CustomFileSystemScanner(IScanFilter ff, IScanFilter df) : base(ff, df) {}
}

I certify that I own, and have sufficient rights to contribute, all source code and related material intended to be compiled or integrated with the source code for the SharpZipLib open source product (the "Contribution"). My Contribution is licensed under the MIT License.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 22, 2021

Codecov Report

❌ Patch coverage is 54.05405% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.90%. Comparing base (612969e) to head (14cdc85).
⚠️ Report is 45 commits behind head on master.

Files with missing lines Patch % Lines
.../ICSharpCode.SharpZipLib/Core/FileSystemScanner.cs 44.44% 30 Missing ⚠️
src/ICSharpCode.SharpZipLib/Zip/FastZip.cs 80.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #678      +/-   ##
==========================================
+ Coverage   73.79%   73.90%   +0.10%     
==========================================
  Files          68       68              
  Lines        8332     8301      -31     
==========================================
- Hits         6149     6135      -14     
+ Misses       2183     2166      -17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member Author

@piksel piksel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs more tests, but otherwise looks OK.

Comment on lines +396 to +397
var subDirectories = GetDirectories(directory)
.Where(d => d != null && directoryFilter_.IsMatch(d));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check direcotryFilter_ for null. Perhaps by

Suggested change
var subDirectories = GetDirectories(directory)
.Where(d => d != null && directoryFilter_.IsMatch(d));
Func<bool, string> filter = directoryFilter_ == null
? (d) => true
: (d) => directoryFilter_.IsMatch(d);
var subDirectories = GetDirectories(directory)
.Where(d => d != null && filter(d));

@piksel piksel self-assigned this Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FastZip.CreateZip crashes when used with certain buggy Directory enumeration on .NET 5

1 participant