Skip to content

Commit a211f19

Browse files
committed
(#23) Prevent creation of empty NuGet.Config file
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.
1 parent f873e60 commit a211f19

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/Core/Configuration/Settings.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,19 @@ public Settings(IFileSystem fileSystem, string fileName, bool isMachineWideSetti
4444
_fileSystem = fileSystem;
4545
_fileName = fileName;
4646
XDocument conf = null;
47-
ExecuteSynchronized(() => conf = XmlUtility.GetOrCreateDocument("configuration", _fileSystem, _fileName));
47+
48+
// As Chocolatey, we never want to create the NuGet.Config file, as this is not used by Chocolatey at all.
49+
// As such, rather than GetOrCreateDocument, if the filepath doesn't exist, simply return the default empty
50+
// XDocument, which is exactly what would have been returned after creating the file.
51+
if (_fileSystem.FileExists(_fileName))
52+
{
53+
ExecuteSynchronized(() => conf = XmlUtility.GetDocument(_fileSystem, _fileName));
54+
}
55+
else
56+
{
57+
conf = new XDocument(new XElement("configuration"));
58+
}
59+
4860
_config = conf;
4961
_isMachineWideSettings = isMachineWideSettings;
5062
}

0 commit comments

Comments
 (0)