Skip to content

Commit 211861c

Browse files
committed
Support ignoring symbols packages
1 parent 835e0f9 commit 211861c

6 files changed

Lines changed: 243 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.IO;
6+
using System.Linq;
7+
8+
namespace NuGet.Server
9+
{
10+
public static class PackageExtensions
11+
{
12+
public static bool IsSymbolsPackage(this IPackage package)
13+
{
14+
var hasSymbols = package.GetFiles()
15+
.Any(pf => string.Equals(Path.GetExtension(pf.Path), ".pdb", StringComparison.InvariantCultureIgnoreCase));
16+
17+
return hasSymbols && package.GetFiles()
18+
.Any(pf => pf.Path.StartsWith("src") || pf.Path.StartsWith("/src"));
19+
}
20+
}
21+
}

src/NuGet.Server/Infrastructure/ServerPackageRepository.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ private void AddPackagesFromDropFolder()
189189
// Create package
190190
var package = new ZipPackage(_fileSystem.OpenFile(packageFile));
191191

192+
// Is it a symbols package?
193+
if (IgnoreSymbolsPackages && package.IsSymbolsPackage())
194+
{
195+
var message = string.Format(Strings.Error_SymbolsPackagesIgnored, package);
196+
197+
_logger.Log(LogLevel.Error, message);
198+
199+
continue;
200+
}
201+
192202
// Allow overwriting package? If not, skip this one.
193203
if (!AllowOverrideExistingPackageOnPush && _expandedPackageRepository.FindPackage(package.Id, package.Version) != null)
194204
{
@@ -237,6 +247,14 @@ public override void AddPackage(IPackage package)
237247
{
238248
_logger.Log(LogLevel.Info, "Start adding package {0} {1}.", package.Id, package.Version);
239249

250+
if (IgnoreSymbolsPackages && package.IsSymbolsPackage())
251+
{
252+
var message = string.Format(Strings.Error_SymbolsPackagesIgnored, package);
253+
254+
_logger.Log(LogLevel.Error, message);
255+
throw new InvalidOperationException(message);
256+
}
257+
240258
if (!AllowOverrideExistingPackageOnPush && FindPackage(package.Id, package.Version) != null)
241259
{
242260
var message = string.Format(NuGetResources.Error_PackageAlreadyExists, package);
@@ -647,6 +665,15 @@ private bool AllowOverrideExistingPackageOnPush
647665
}
648666
}
649667

668+
private bool IgnoreSymbolsPackages
669+
{
670+
get
671+
{
672+
// If the setting is misconfigured, treat it as "false" (backwards compatibility).
673+
return _getSetting("ignoreSymbolsPackages", false);
674+
}
675+
}
676+
650677
private bool EnableDelisting
651678
{
652679
get

src/NuGet.Server/NuGet.Server.csproj

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Compile Include="Core\DefaultServiceResolver.cs" />
7777
<Compile Include="Core\FrameworkNameExtensions.cs" />
7878
<Compile Include="Core\IServiceResolver.cs" />
79+
<Compile Include="Core\PackageExtensions.cs" />
7980
<Compile Include="DataServices\ODataPackage.cs" />
8081
<Compile Include="DataServices\PackageContext.cs" />
8182
<Compile Include="DataServices\PackageExtensions.cs" />
@@ -109,6 +110,11 @@
109110
<Compile Include="DataServices\QueryableExtensions.cs" />
110111
<Compile Include="DataServices\QueryTranslator.cs" />
111112
<Compile Include="DataServices\QueryTranslatorProvider.cs" />
113+
<Compile Include="Strings.Designer.cs">
114+
<AutoGen>True</AutoGen>
115+
<DesignTime>True</DesignTime>
116+
<DependentUpon>Strings.resx</DependentUpon>
117+
</Compile>
112118
</ItemGroup>
113119
<ItemGroup>
114120
<Content Include="Default.aspx" />
@@ -139,7 +145,12 @@
139145
<SubType>Designer</SubType>
140146
</Content>
141147
</ItemGroup>
142-
<ItemGroup />
148+
<ItemGroup>
149+
<EmbeddedResource Include="Strings.resx">
150+
<Generator>ResXFileCodeGenerator</Generator>
151+
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
152+
</EmbeddedResource>
153+
</ItemGroup>
143154
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
144155
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
145156
</PropertyGroup>

src/NuGet.Server/Strings.Designer.cs

Lines changed: 72 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.Server/Strings.resx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 1.3
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">1.3</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1">this is my long string</data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
[base64 mime encoded serialized .NET Framework object]
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
[base64 mime encoded string representing a byte array form of the .NET Framework object]
27+
</data>
28+
29+
There are any number of "resheader" rows that contain simple
30+
name/value pairs.
31+
32+
Each data row contains a name, and value. The row also contains a
33+
type or mimetype. Type corresponds to a .NET class that support
34+
text/value conversion through the TypeConverter architecture.
35+
Classes that don't support this are serialized and stored with the
36+
mimetype set.
37+
38+
The mimetype is used for serialized objects, and tells the
39+
ResXResourceReader how to depersist the object. This is currently not
40+
extensible. For a given mimetype the value must be set accordingly:
41+
42+
Note - application/x-microsoft.net.object.binary.base64 is the format
43+
that the ResXResourceWriter will generate, however the reader can
44+
read any of the formats listed below.
45+
46+
mimetype: application/x-microsoft.net.object.binary.base64
47+
value : The object must be serialized with
48+
: System.Serialization.Formatters.Binary.BinaryFormatter
49+
: and then encoded with base64 encoding.
50+
51+
mimetype: application/x-microsoft.net.object.soap.base64
52+
value : The object must be serialized with
53+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
54+
: and then encoded with base64 encoding.
55+
56+
mimetype: application/x-microsoft.net.object.bytearray.base64
57+
value : The object must be serialized into a byte array
58+
: using a System.ComponentModel.TypeConverter
59+
: and then encoded with base64 encoding.
60+
-->
61+
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:element name="root" msdata:IsDataSet="true">
64+
<xsd:complexType>
65+
<xsd:choice maxOccurs="unbounded">
66+
<xsd:element name="data">
67+
<xsd:complexType>
68+
<xsd:sequence>
69+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
70+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
73+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
74+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
75+
</xsd:complexType>
76+
</xsd:element>
77+
<xsd:element name="resheader">
78+
<xsd:complexType>
79+
<xsd:sequence>
80+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
81+
</xsd:sequence>
82+
<xsd:attribute name="name" type="xsd:string" use="required" />
83+
</xsd:complexType>
84+
</xsd:element>
85+
</xsd:choice>
86+
</xsd:complexType>
87+
</xsd:element>
88+
</xsd:schema>
89+
<resheader name="resmimetype">
90+
<value>text/microsoft-resx</value>
91+
</resheader>
92+
<resheader name="version">
93+
<value>1.3</value>
94+
</resheader>
95+
<resheader name="reader">
96+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
97+
</resheader>
98+
<resheader name="writer">
99+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
100+
</resheader>
101+
<data name="Error_SymbolsPackagesIgnored" xml:space="preserve">
102+
<value>Package {0} is a symbols package (it contains .pdb fiels and a /src folder). Symbols packages are ignored on this server.</value>
103+
</data>
104+
</root>

src/NuGet.Server/Web.config

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
Set allowOverrideExistingPackageOnPush to false if attempts to upload a package that already exists
2727
(same id and same version) should fail.
2828
-->
29-
<add key="allowOverrideExistingPackageOnPush" value="false" />
29+
<add key="allowOverrideExistingPackageOnPush" value="true" />
30+
31+
<!--
32+
Set ignoreSymbolsPackages to true to filter out symbols packages.
33+
When enabled, files named `.symbols.nupkg` or packages containing a `/src` folder will be ignored.
34+
-->
35+
<add key="ignoreSymbolsPackages" value="false" />
3036

3137
<!--
3238
Set enableDelisting to true to enable delist instead of delete as a result of a "nuget delete" command.

0 commit comments

Comments
 (0)