diff --git a/DiskAccessLibrary/FileSystems/NTFS/Adapters/NTFSFileSystem.cs b/DiskAccessLibrary/FileSystems/NTFS/Adapters/NTFSFileSystem.cs index d06b9b0..319f203 100644 --- a/DiskAccessLibrary/FileSystems/NTFS/Adapters/NTFSFileSystem.cs +++ b/DiskAccessLibrary/FileSystems/NTFS/Adapters/NTFSFileSystem.cs @@ -108,25 +108,24 @@ public override Stream OpenFile(string path, FileMode mode, FileAccess access, F { } - if (mode == FileMode.CreateNew) + if (fileExists) { - if (fileExists) + if (mode == FileMode.CreateNew) { throw new AlreadyExistsException(); } + else if (mode == FileMode.Create) + { + mode = FileMode.Truncate; + } } - - if (!fileExists) + else { string directoryPath = Path.GetDirectoryName(path); string fileName = Path.GetFileName(path); FileRecord directoryRecord = m_volume.GetFileRecord(directoryPath); fileRecord = m_volume.CreateFile(directoryRecord.BaseSegmentReference, fileName, false); } - else if (mode == FileMode.Create) - { - mode = FileMode.Truncate; - } } else // Open, Truncate or Append {