From 377663c2e52c30a130218e80ddbcc2cc6e4c1796 Mon Sep 17 00:00:00 2001 From: duckdoom4 <60387522+duckdoom4@users.noreply.github.com> Date: Wed, 20 Sep 2023 07:13:11 +0200 Subject: [PATCH] Make sure we open with the requested access --- pkNX.Containers/VFS/FileSystems/LayeredFileSystem.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkNX.Containers/VFS/FileSystems/LayeredFileSystem.cs b/pkNX.Containers/VFS/FileSystems/LayeredFileSystem.cs index 917a2da7..2b8808d2 100644 --- a/pkNX.Containers/VFS/FileSystems/LayeredFileSystem.cs +++ b/pkNX.Containers/VFS/FileSystems/LayeredFileSystem.cs @@ -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;