Skip to content

Commit bf0e305

Browse files
fix: truncating pre-existing output file when overwritten (#315)
See also here: https://stackoverflow.com/questions/3653132/file-openwrite-appends-instead-of-wiping-contents Closes: #255 Closes: #329 --------- Signed-off-by: andreas hilti <[email protected]>
1 parent 8e3dbeb commit bf0e305

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/cyclonedx/CliUtils.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public static async Task<int> OutputBomHelper(Bom bom, CycloneDXBomFormat format
154154
}
155155
}
156156

157-
using var stream = filename == null ? Console.OpenStandardOutput() : File.OpenWrite(filename);
157+
using var stream = filename == null ? Console.OpenStandardOutput() : File.Create(filename);
158158

159159
switch (format)
160160
{
@@ -193,7 +193,7 @@ public static async Task<int> OutputBomHelper(Bom bom, ConvertFormat format, Spe
193193

194194
bom.SpecVersion = outputVersion.HasValue ? outputVersion.Value : SpecificationVersionHelpers.CurrentVersion;
195195

196-
using var stream = filename == null ? Console.OpenStandardOutput() : File.OpenWrite(filename);
196+
using var stream = filename == null ? Console.OpenStandardOutput() : File.Create(filename);
197197

198198
switch (format)
199199
{

0 commit comments

Comments
 (0)