Skip to content

Commit 5be3993

Browse files
committed
Preserve nuget.config file casing after cleanup
1 parent 26cea33 commit 5be3993

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackages.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,24 @@ public void Dispose()
255255

256256
try
257257
{
258-
File.Delete(nugetConfigPath);
258+
if (backupNugetConfig is null)
259+
{
260+
logger.LogInfo("Removing nuget.config file");
261+
File.Delete(nugetConfigPath);
262+
return;
263+
}
259264

260-
if (backupNugetConfig is not null)
265+
logger.LogInfo("Reverting nuget.config file content");
266+
// The content of the original nuget.config file is reverted without changing the file's attributes or casing:
267+
using (var backup = File.OpenRead(backupNugetConfig))
268+
using (var current = File.OpenWrite(nugetConfigPath))
261269
{
262-
File.Move(backupNugetConfig, nugetConfigPath);
270+
current.SetLength(0);
271+
backup.CopyTo(current);
263272
}
273+
274+
logger.LogInfo("Deleting backup nuget.config file");
275+
File.Delete(backupNugetConfig);
264276
}
265277
catch (Exception exc)
266278
{

0 commit comments

Comments
 (0)