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 atomically creating and opening a file #10

Closed
manuelroemer opened this issue May 31, 2020 · 2 comments · Fixed by #26
Closed

Add support for atomically creating and opening a file #10

manuelroemer opened this issue May 31, 2020 · 2 comments · Fixed by #26
Labels
enhancement New feature or request

Comments

@manuelroemer
Copy link
Owner

manuelroemer commented May 31, 2020

New Feature Proposal

Description

The StorageFile.CreateAsync method currently doesn't open a Stream. This is done on purpose to prevent situations where a Stream is not disposed. However, in certain situations, one wants to atomically create and open the file, e.g. for creating lock files. Files should therefore provide both options.

Discussion

The naming is open, but I'm leaning towards StorageFile.CreateAndOpenAsync(CreationCollisionOption, CancellationToken).

This change also makes sense together with #9, since #9 might add new parameters to the OpenAsync method. This parameter should then be mirrored.

The new method can also be implemented without introducing a breaking change by making it virtual instead of abstract. The default implementation in StorageFile could then call CreateAsync and OpenAsync in order. This is not atomic, but perhaps the best possible implementation for certain file systems.

@manuelroemer manuelroemer added the enhancement New feature or request label May 31, 2020
@manuelroemer
Copy link
Owner Author

Closing for now. See this comment for the reasons.

Additional info:
I initially thought of this feature for the purpose of atomically acquiring a file lock. With FileShare being discarded for now, file locks are basically gone. Therefore, this feature is also less pressing.

With that being said, it might also make sense in other, non file locking related scenarios. If anyone has a need for this feature, please comment. Adding it is still possible (just less pressing for myself right now).

@manuelroemer
Copy link
Owner Author

I've now reached a point where I want to have support for a method like this. Even though atomicity cannot be guaranteed, having it is incredibly convenient in most situations. Therefore reopening this issue.

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