Skip to content

Commit

Permalink
Merge pull request #5 from AronMarinelli/user/aron/fix-default-appset…
Browse files Browse the repository at this point in the history
…tings

Fix creation of default appsettings by properly disposing FileStream/StreamWriter
  • Loading branch information
AronMarinelli authored Apr 8, 2024
2 parents 1e41407 + c4597f0 commit f78dfd7
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions Bitwarden.SecureSync.Application/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ static async Task CheckConfigurationAvailability()
);

var fileInfo = new FileInfo("config/appsettings.json");
await using var fs = fileInfo.Open(FileMode.CreateNew, FileAccess.ReadWrite);
await using var sw = new StreamWriter(fs);
await sw.WriteAsync(serializedSampleConfig);

Console.WriteLine($"Stopping application gracefully. Please add required configuration to {fileInfo.FullName} in order for the application to run properly on next run.");
if (fileInfo.Directory != null && !fileInfo.Directory.Exists)
Directory.CreateDirectory(fileInfo.Directory.FullName);

await using (var fs = fileInfo.Open(FileMode.CreateNew, FileAccess.ReadWrite))
await using (var sw = new StreamWriter(fs))
{
await sw.WriteAsync(serializedSampleConfig);
}

Console.WriteLine(
$"Stopping application gracefully. Please add required configuration to {fileInfo.FullName} in order for the application to run properly on next run.");
Environment.Exit(0);
}

Expand Down

0 comments on commit f78dfd7

Please sign in to comment.