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

ZipArchiveFS DirectoryExists doesn't work as expected #79

Closed
Banane9 opened this issue Oct 17, 2023 · 3 comments · Fixed by #88
Closed

ZipArchiveFS DirectoryExists doesn't work as expected #79

Banane9 opened this issue Oct 17, 2023 · 3 comments · Fixed by #88
Labels

Comments

@Banane9
Copy link

Banane9 commented Oct 17, 2023

Unless DirectoryEntries have been created using Zio, DirectoryExists on ZipArchiveFileSystems will return false for any path except the root, despite files containing the path existing.

While zip files themselves have no notion of directories, it is inconsistent and inconvenient if this is not handled uniformly by this abstration layer.

This is occuring while using Zio as a NuGet package on .net 4.6.2

@Banane9
Copy link
Author

Banane9 commented Oct 17, 2023

Okay, can't even Open any files, even with paths returned by EnumeratePaths (which also doesn't work outside of the root folder).

I suspect it has to do with the conditionals replacing / with \ only for .net 4.5, but nothing else and another version of the package being used on .net 4.6.2 by default.

@Banane9
Copy link
Author

Banane9 commented Oct 17, 2023

Okay - it was actually the opposite.

Forcing it to use the netstandard2.0 version made accessing files work, at least. Haven't checked the directory test.

@xoofx xoofx added the question label Dec 10, 2023
@GerardSmit
Copy link
Contributor

GerardSmit commented Dec 11, 2023

Maybe related, in ZipArchiveFileSystem.cs there is a comment:

// .Net4.5 uses a backslash as directory separator.

and then the string is fullname is being replaced with the correct separator:

#if NETFRAMEWORK // .Net4.5 uses a backslash as directory separator
foreach (var entry in _archive.Entries)
{
entry.FullName.Replace('/', DirectorySeparator);
}
#else
foreach (var entry in _archive.Entries)
{
entry.FullName.Replace('\\', DirectorySeparator);
}
#endif

However, .Replace returns a new string; it doesn't manipulate the current string. So the result is never being used.

I think this code has to be moved into the .ToDictionary:

_entries = _archive.Entries.ToDictionary(e => e.FullName.ToLowerInvariant(), e => e);

To for example:

_entries = _archive.Entries.ToDictionary(e =>
{
#if NETFRAMEWORK // .Net4.5 uses a backslash as directory separator 
    var fullName = e.FullName.Replace('/', DirectorySeparator);
#else 
    var fullName = e.FullName.Replace('\\', DirectorySeparator); 
#endif 

    return fullName.ToLowerInvariant();
}, e => e); 

However, if you install the NuGet package as .NET Standard 2.0 in .NET Framework, it will use the '\\'-separator. I'm not sure if that's a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants