From 9158002a42fd81f3b7d93063ccce7a79d6a2bd67 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Wed, 15 Sep 2021 11:18:32 -0700 Subject: [PATCH] Properly truncate files --- BeefLibs/corlib/src/IO/FileMode.bf | 12 ++++++------ BeefLibs/corlib/src/IO/FileStream.bf | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/BeefLibs/corlib/src/IO/FileMode.bf b/BeefLibs/corlib/src/IO/FileMode.bf index 10719cad..4c1eee80 100644 --- a/BeefLibs/corlib/src/IO/FileMode.bf +++ b/BeefLibs/corlib/src/IO/FileMode.bf @@ -17,16 +17,16 @@ namespace System.IO /// Opens an existing file. Fails if the file does not exist. Open = 3, - // Opens the file if it exists. Otherwise, creates a new file. + /// Opens the file if it exists. Otherwise, creates a new file. OpenOrCreate = 4, - // Opens an existing file. Once opened, the file is truncated so that its - // size is zero bytes. The calling process must open the file with at least - // WRITE access. Fails if the file does not exist. + /// Opens an existing file. Once opened, the file is truncated so that its + /// size is zero bytes. The calling process must open the file with at least + /// WRITE access. Fails if the file does not exist. Truncate = 5, - // Opens the file if it exists and seeks to the end. Otherwise, - // creates a new file. + /// Opens the file if it exists and seeks to the end. Otherwise, + /// creates a new file. Append = 6, } } diff --git a/BeefLibs/corlib/src/IO/FileStream.bf b/BeefLibs/corlib/src/IO/FileStream.bf index 9df7f8a3..0be6c773 100644 --- a/BeefLibs/corlib/src/IO/FileStream.bf +++ b/BeefLibs/corlib/src/IO/FileStream.bf @@ -175,12 +175,13 @@ namespace System.IO createKind = .CreateIfNotExists; case .Create: createKind = .CreateAlways; + createFlags |= .Truncate; case .Open: createKind = .OpenExisting; case .OpenOrCreate: createKind = .OpenAlways; case .Truncate: - createKind = .CreateAlways; + createKind = .OpenExisting; createFlags |= .Truncate; case .Append: createKind = .CreateAlways;