You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Breaking change]: On Linux, opening a file without FileAccess.Write then locking it, will now lock it with a shared lock #26529
On Unix, when the user opens a file using FileStream, only with a read-only FileAccess permission (no FileAccess.Write), and then attempts to lock a region of the file using FileStream.Lock, the operation should succeed because the file will be locked with a shared or read lock.
using(FileStreamfs=File.OpenRead("testfile"))// Opening with FileAccess.Read only{fs.Lock((long)3,(long)1);// Attempting to lock a region of the read-only file}
Version
.NET 6 RC 1
Previous behavior
On Unix, when the user opened a file with FileStream with read permissions only, and then attempted to lock a region of the file using FileStream.Lock, we would attempt to lock the file with a write-lock, which would throw System.UnauthorizedException: Access to the path is denied. .
No exception thrown on Windows (code behaved well).
New behavior
Now, when the user opens a file using FileStream with read permissions only on Unix, and then attempts to lock a region of the file using FileStream.Lock, we lock the file with a read lock (also known as shared lock). No behavior change on Windows.
Type of breaking change
Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
Reason for change
FileStream.Lock(long position, long length) is the API we offer to users that want to lock a specific region of a file. We do not offer an API that lets the user choose the underlying locking method, so the user expects this API to correctly determine what is the appropriate locking method depending on the file permissions. The user does not have an easy workaround for this.
Recommended action
Before .NET 6.0, in order to be able to lock the file, the user would have to either check if the code was being executed in Windows or the FileStream was opened with FileAccess.Write permission, or wrap the FileStream.Lock call with a try catch to capture the System.UnauthorizedException.
On .NET 6.0 and above, such workarounds will not be necessary.
Activity