unosquare / embedio

A tiny, cross-platform, module based web server for .NET
http://unosquare.github.io/embedio
Other
1.45k stars 175 forks source link

WithZipFile should open a read only handle(or have the option to) #573

Open jswigart opened 1 year ago

jswigart commented 1 year ago

Describe the bug The built in WithZipFile extension method provides no mechanism for the user to open the zip file in read only mode, which is problematic if you have another instance of the map, or external tooling, also wanting to read the archive in read only mode.

To Reproduce Steps to reproduce the behavior:

  1. Create an app that maps a module WithZipFile
  2. Run it multiple times, the 2nd will fail because the first has a write access lock on the file

Expected behavior Expect to be able to open a zip file in read only mode. If the ZipFileProvider doesn't support writing at all, then the WithZipFile should just hard code to read only, as there is no reason for a write lock to be held.

Additional context This was discussed a bit in slack for more information on October 24th, 2022

rdeago commented 1 year ago

Hello @jswigart, thanks for opening this issue.

Non-literally quoting myself from Slack:

The zip file is opened with FileAccess.ReadWrite and FileShare.Read (the default): https://source.dot.net/#System.Private.CoreLib/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs,120 We should use FileAccess.Read in the constructor call, as ReadWrite is not actualy needed.

There's no need for an option, as EmbedIO considers a Zip file an immutable file provider.

While we're on the subject, it wouldn't hurt to specify FileShare.Read explicitly too.

rdeago commented 1 year ago

This is the line to fix in version 3 (branch v3.x).

This is the line to fix in version 4 (branch master).

Any kind soul willing to submit a PR?