Skip to content

Commit 835e0f9

Browse files
committed
Do not overwrite packages when scanning drop folder for new packages
1 parent 834202f commit 835e0f9

2 files changed

Lines changed: 30 additions & 18 deletions

File tree

src/NuGet.Server/Infrastructure/ServerPackageRepository.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,20 @@ 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+
// Allow overwriting package? If not, skip this one.
193+
if (!AllowOverrideExistingPackageOnPush && _expandedPackageRepository.FindPackage(package.Id, package.Version) != null)
194+
{
195+
var message = string.Format(NuGetResources.Error_PackageAlreadyExists, package);
196+
197+
_logger.Log(LogLevel.Error, message);
198+
199+
continue;
200+
}
201+
202+
// Copy to correct filesystem location
191203
_expandedPackageRepository.AddPackage(package);
192204
_fileSystem.DeleteFile(packageFile);
193205

src/NuGet.Server/Web.config

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,41 @@
66
<configuration>
77
<appSettings>
88
<!--
9-
Determines if an Api Key is required to push\delete packages from the server.
9+
Determines if an Api Key is required to push\delete packages from the server.
1010
-->
1111
<add key="requireApiKey" value="true" />
1212

1313
<!--
14-
Set the value here to allow people to push/delete packages from the server.
15-
NOTE: This is a shared key (password) for all users.
14+
Set the value here to allow people to push/delete packages from the server.
15+
NOTE: This is a shared key (password) for all users.
1616
-->
1717
<add key="apiKey" value="" />
1818

1919
<!--
20-
Change the path to the packages folder. Default is ~/Packages.
21-
This can be a virtual or physical path.
20+
Change the path to the packages folder. Default is ~/Packages.
21+
This can be a virtual or physical path.
2222
-->
2323
<add key="packagesPath" value="" />
2424

2525
<!--
26-
Set allowOverrideExistingPackageOnPush to false if attempts to upload a package that already exists
27-
(same id and same version) should fail.
26+
Set allowOverrideExistingPackageOnPush to false if attempts to upload a package that already exists
27+
(same id and same version) should fail.
2828
-->
29-
<add key="allowOverrideExistingPackageOnPush" value="true" />
29+
<add key="allowOverrideExistingPackageOnPush" value="false" />
3030

3131
<!--
32-
Set enableDelisting to true to enable delist instead of delete as a result of a "nuget delete" command.
33-
- delete: package is deleted from the repository's local filesystem.
34-
- delist:
35-
- "nuget delete": the "hidden" file attribute of the corresponding nupkg on the repository local filesystem is turned on instead of deleting the file.
36-
- "nuget list" skips delisted packages, i.e. those that have the hidden attribute set on their nupkg.
37-
- "nuget install packageid -version version" command will succeed for both listed and delisted packages.
38-
e.g. delisted packages can still be downloaded by clients that explicitly specify their version.
32+
Set enableDelisting to true to enable delist instead of delete as a result of a "nuget delete" command.
33+
- delete: package is deleted from the repository's local filesystem.
34+
- delist:
35+
- "nuget delete": the "hidden" file attribute of the corresponding nupkg on the repository local filesystem is turned on instead of deleting the file.
36+
- "nuget list" skips delisted packages, i.e. those that have the hidden attribute set on their nupkg.
37+
- "nuget install packageid -version version" command will succeed for both listed and delisted packages.
38+
e.g. delisted packages can still be downloaded by clients that explicitly specify their version.
3939
-->
4040
<add key="enableDelisting" value="false" />
41-
41+
4242
<!--
43-
Set enableFrameworkFiltering to true to enable filtering packages by their supported frameworks during search.
43+
Set enableFrameworkFiltering to true to enable filtering packages by their supported frameworks during search.
4444
-->
4545
<add key="enableFrameworkFiltering" value="false" />
4646
</appSettings>

0 commit comments

Comments
 (0)