Skip to content

Commit 4a1b673

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/dev'
2 parents 0b1ed57 + 211861c commit 4a1b673

9 files changed

Lines changed: 291 additions & 19 deletions

File tree

src/NuGet.Server/Core/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static string GetRepositoryUrl(Uri currentUrl, string applicationPath)
1414

1515
public static string GetPushUrl(Uri currentUrl, string applicationPath)
1616
{
17-
return GetBaseUrl(currentUrl, applicationPath);
17+
return GetBaseUrl(currentUrl, applicationPath) + "nuget";
1818
}
1919

2020
public static string GetBaseUrl(Uri currentUrl, string applicationPath)
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/DataServices/Routes.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ private static void MapRoutes(RouteCollection routes)
5757
context => CreatePackageService().ClearCache(context.HttpContext));
5858

5959
#if DEBUG
60+
// Route to create a new package(http://{root}/nuget)
61+
routes.MapDelegate("CreatePackageNuGet",
62+
"nuget",
63+
new { httpMethod = new HttpMethodConstraint("PUT") },
64+
context => CreatePackageService().CreatePackage(context.HttpContext));
65+
6066
// The default route is http://{root}/nuget/Packages
6167
var factory = new DataServiceHostFactory();
6268
var serviceRoute = new ServiceRoute("nuget", factory, typeof(Packages));

src/NuGet.Server/DataServices/Routes.cs.pp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Web.Routing;
44
using NuGet.Server;
55
using NuGet.Server.DataServices;
6+
using NuGet.Server.Publishing;
7+
using RouteMagic;
68

79
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof($rootnamespace$.NuGetRoutes), "Start")]
810

@@ -15,12 +17,23 @@
1517
}
1618

1719
private static void MapRoutes(RouteCollection routes) {
20+
// Route to create a new package(http://{root}/nuget)
21+
routes.MapDelegate("CreatePackageNuGet",
22+
"nuget",
23+
new { httpMethod = new HttpMethodConstraint("PUT") },
24+
context => CreatePackageService().CreatePackage(context.HttpContext));
25+
1826
// The default route is http://{root}/nuget/Packages
1927
var factory = new DataServiceHostFactory();
2028
var serviceRoute = new ServiceRoute("nuget", factory, typeof(Packages));
2129
serviceRoute.Defaults = new RouteValueDictionary { { "serviceType", "odata" } };
2230
serviceRoute.Constraints = new RouteValueDictionary { { "serviceType", "odata" } };
2331
routes.Add("nuget", serviceRoute);
2432
}
33+
34+
private static IPackageService CreatePackageService()
35+
{
36+
return ServiceResolver.Resolve<IPackageService>();
37+
}
2538
}
2639
}

src/NuGet.Server/Infrastructure/ServerPackageRepository.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,30 @@ private void AddPackagesFromDropFolder()
186186
{
187187
try
188188
{
189-
// Copy to correct filesystem location
189+
// Create package
190190
var package = new ZipPackage(_fileSystem.OpenFile(packageFile));
191+
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+
202+
// Allow overwriting package? If not, skip this one.
203+
if (!AllowOverrideExistingPackageOnPush && _expandedPackageRepository.FindPackage(package.Id, package.Version) != null)
204+
{
205+
var message = string.Format(NuGetResources.Error_PackageAlreadyExists, package);
206+
207+
_logger.Log(LogLevel.Error, message);
208+
209+
continue;
210+
}
211+
212+
// Copy to correct filesystem location
191213
_expandedPackageRepository.AddPackage(package);
192214
_fileSystem.DeleteFile(packageFile);
193215

@@ -225,6 +247,14 @@ public override void AddPackage(IPackage package)
225247
{
226248
_logger.Log(LogLevel.Info, "Start adding package {0} {1}.", package.Id, package.Version);
227249

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+
228258
if (!AllowOverrideExistingPackageOnPush && FindPackage(package.Id, package.Version) != null)
229259
{
230260
var message = string.Format(NuGetResources.Error_PackageAlreadyExists, package);
@@ -635,6 +665,15 @@ private bool AllowOverrideExistingPackageOnPush
635665
}
636666
}
637667

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+
638677
private bool EnableDelisting
639678
{
640679
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>

0 commit comments

Comments
 (0)