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

Add support for FileShare when opening a file #9

Closed
manuelroemer opened this issue May 31, 2020 · 3 comments
Closed

Add support for FileShare when opening a file #9

manuelroemer opened this issue May 31, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@manuelroemer
Copy link
Owner

manuelroemer commented May 31, 2020

New Feature Proposal

Description

Most file systems support the concept of .NET's FileShare enumeration, meaning that an opened file can be accessed by 1:N other streams. Currently, Files defaults to the FileShare.None value in the implementations because UWP doesn't support FileShare. Nontheless, it would be awesome to have support for it, e.g. for lock files.

Discussion

The reason why it's not here yet is UWP which doesn't support FileShare. Of course, UWP should not be a blocker for important APIs. We could go the same route as with the FileAttributes and simply take the FileShare as a suggestion. This means that Files doesn't guarantee that the FileShare is used (and therefore doesn't, for example, add it to the specification tests). This could obviously be confusing from time to time, so who knows it it's a good idea.
As a supporting point for this behavior, FileShare.Inheritable is not supported by Win32, so there's similar behavior.

@manuelroemer
Copy link
Owner Author

There is actually a way to support FileShare in UWP via the StorageFile.CreateSafeFileHandle extension. This totally makes this feature realizable.

@manuelroemer manuelroemer self-assigned this May 31, 2020
@manuelroemer manuelroemer mentioned this issue Jun 1, 2020
5 tasks
@manuelroemer manuelroemer linked a pull request Jun 1, 2020 that will close this issue
5 tasks
@manuelroemer
Copy link
Owner Author

Something I wasn't aware of is that FileShare is not supported by the Unix variations of .NET Core. As the first CI run of #11 shows, the most basic FileShare tests on Unix are failing because the underlying .NET runtime (and Unix itself) doesn't support the file locking concepts.

Imo, this destroys the whole idea of adding FileShare support. Here, I agree with this comment - if it cannot be guaranteed that FileShare works in all cases it's better to not include it at all. Since FileShare is most likely used to prevent data corruption, it not working could prove fatal in certain cases.

Ultimately, the goal of Files is to provide a file system implementation which is both easy to use and predictable. The latter would not be fulfilled by adding FileShare support.

To any readers: Feel free to comment on the situation/if you feel that FileShare is crucial. Given the right arguments, this could potentially be added in the future.

@manuelroemer
Copy link
Owner Author

Last note: I will keep the implementation of #11 in the branch feature/FileShare-Support (i.e. I won't delete that branch) because certain aspects of it (e.g. the UWP implementation) are really interesting. I don't want to lose these changes in case this issue gets re-opened for some reasons.

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

Successfully merging a pull request may close this issue.

1 participant