mirror of
https://github.com/kwsch/pkNX.git
synced 2026-09-30 13:16:58 -05:00
Make sure we open with the requested access
This commit is contained in:
@@ -134,14 +134,17 @@ public Stream OpenFile(FileSystemPath path, FileMode mode = FileMode.Open, FileA
|
||||
// The file exists, now we need to check if we can open it with the requested access
|
||||
// readonly fs requires special handling for write requests.
|
||||
// if readonly access is requested, we can open it if the fs is readonly
|
||||
if (!fs.IsReadOnly)
|
||||
return fs.OpenFile(path, FileMode.Open, access);
|
||||
|
||||
var readStream = fs.OpenFile(path);
|
||||
if (!fs.IsReadOnly || access == FileAccess.Read)
|
||||
if (access == FileAccess.Read)
|
||||
return readStream;
|
||||
|
||||
// For write-only access, we can just create a new empty file
|
||||
IFileSystem writableFs = GetFirstWritable();
|
||||
writableFs.CreateDirectoryRecursive(path.ParentPath);
|
||||
var writeStream = writableFs.CreateFile(path);
|
||||
var writeStream = writableFs.OpenFile(path, FileMode.Create, access);
|
||||
|
||||
if (access == FileAccess.Write)
|
||||
return writeStream;
|
||||
|
||||
Reference in New Issue
Block a user