Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fastzip): allow custom filesystemscanner #678

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

piksel
Copy link
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

codecov bot commented Oct 22, 2021

Codecov Report

Merging #678 (14cdc85) into master (612969e) will increase coverage by 0.10%.
The diff coverage is 54.05%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
.../ICSharpCode.SharpZipLib/Core/FileSystemScanner.cs 49.50% <44.44%> (+0.76%) ⬆️
src/ICSharpCode.SharpZipLib/Zip/FastZip.cs 59.78% <80.00%> (+0.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 612969e...14cdc85. Read the comment docs.

Copy link
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
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