Skip to content

Commit

Permalink
(#23) Prevent creation of empty NuGet.Config file
Browse files Browse the repository at this point in the history
As Chocolatey, we never want to create the NuGet.Config file, as this is
not used by Chocolatey at all. As such, rather than GetOrCreateDocument,
if the filepath doesn't exist, simply return the default empty
XDocument, which is exactly what would have been returned after creating
the file.

The existing coding style has been adhered to here, and as little
changes as possible have been made.
  • Loading branch information
gep13 committed May 6, 2021
1 parent f873e60 commit a211f19
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Core/Configuration/Settings.cs
Expand Up @@ -44,7 +44,19 @@ public Settings(IFileSystem fileSystem, string fileName, bool isMachineWideSetti
_fileSystem = fileSystem;
_fileName = fileName;
XDocument conf = null;
ExecuteSynchronized(() => conf = XmlUtility.GetOrCreateDocument("configuration", _fileSystem, _fileName));

// As Chocolatey, we never want to create the NuGet.Config file, as this is not used by Chocolatey at all.
// As such, rather than GetOrCreateDocument, if the filepath doesn't exist, simply return the default empty
// XDocument, which is exactly what would have been returned after creating the file.
if (_fileSystem.FileExists(_fileName))
{
ExecuteSynchronized(() => conf = XmlUtility.GetDocument(_fileSystem, _fileName));
}
else
{
conf = new XDocument(new XElement("configuration"));
}

_config = conf;
_isMachineWideSettings = isMachineWideSettings;
}
Expand Down

0 comments on commit a211f19

Please sign in to comment.