Skip to content

Commit bf717c1

Browse files
committed
Merge branch 'dev' into master
2 parents f507bd2 + 0f46245 commit bf717c1

5 files changed

Lines changed: 47 additions & 2 deletions

File tree

src/NuGet.Server.Core/Infrastructure/ServerPackageRepository.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class ServerPackageRepository
3232

3333
private readonly bool _runBackgroundTasks;
3434
private FileSystemWatcher _fileSystemWatcher;
35+
private string _watchDirectory;
3536
private bool _isFileSystemWatcherSuppressed;
3637
private bool _needsRebuild;
3738

@@ -548,6 +549,9 @@ private void RegisterFileSystemWatcher()
548549
IncludeSubdirectories = true,
549550
};
550551

552+
//Keep the normalized watch path.
553+
_watchDirectory = Path.GetFullPath(_fileSystemWatcher.Path);
554+
551555
_fileSystemWatcher.Changed += FileSystemChangedAsync;
552556
_fileSystemWatcher.Created += FileSystemChangedAsync;
553557
_fileSystemWatcher.Deleted += FileSystemChangedAsync;
@@ -576,6 +580,8 @@ private void UnregisterFileSystemWatcher()
576580

577581
_logger.Log(LogLevel.Verbose, "Destroyed FileSystemWatcher - no longer monitoring {0}.", Source);
578582
}
583+
584+
_watchDirectory = null;
579585
}
580586

581587

@@ -593,16 +599,24 @@ private async void FileSystemChangedAsync(object sender, FileSystemEventArgs e)
593599

594600
_logger.Log(LogLevel.Verbose, "File system changed. File: {0} - Change: {1}", e.Name, e.ChangeType);
595601

602+
var changedDirectory = Path.GetDirectoryName(e.FullPath);
603+
if (changedDirectory == null || _watchDirectory == null)
604+
{
605+
return;
606+
}
607+
608+
changedDirectory = Path.GetFullPath(changedDirectory);
609+
596610
// 1) If a .nupkg is dropped in the root, add it as a package
597-
if (string.Equals(Path.GetDirectoryName(e.FullPath), _fileSystemWatcher.Path, StringComparison.OrdinalIgnoreCase)
611+
if (string.Equals(changedDirectory, _watchDirectory, StringComparison.OrdinalIgnoreCase)
598612
&& string.Equals(Path.GetExtension(e.Name), ".nupkg", StringComparison.OrdinalIgnoreCase))
599613
{
600614
// When a package is dropped into the server packages root folder, add it to the repository.
601615
await AddPackagesFromDropFolderAsync(CancellationToken.None);
602616
}
603617

604618
// 2) If a file is updated in a subdirectory, *or* a folder is deleted, invalidate the cache
605-
if ((!string.Equals(Path.GetDirectoryName(e.FullPath), _fileSystemWatcher.Path, StringComparison.OrdinalIgnoreCase) && File.Exists(e.FullPath))
619+
if ((!string.Equals(changedDirectory, _watchDirectory, StringComparison.OrdinalIgnoreCase) && File.Exists(e.FullPath))
606620
|| e.ChangeType == WatcherChangeTypes.Deleted)
607621
{
608622
// TODO: invalidating *all* packages for every nupkg change under this folder seems more expensive than it should.

src/NuGet.Server/App_Start/NuGetODataConfig.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
using System.Net.Http;
55
using System.Web.Http;
6+
using System.Web.Http.ExceptionHandling;
67
using System.Web.Http.Routing;
78
using NuGet.Server.DataServices;
9+
using NuGet.Server.Infrastructure;
810
using NuGet.Server.V2;
911

1012
// The consuming project executes this logic with its own copy of this class. This is done with a .pp file that is
@@ -28,6 +30,11 @@ public static void Initialize(HttpConfiguration config, string controllerName)
2830
{
2931
NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", controllerName);
3032

33+
config.Services.Replace(typeof(IExceptionLogger), new TraceExceptionLogger());
34+
35+
// Trace.Listeners.Add(new TextWriterTraceListener(HostingEnvironment.MapPath("~/NuGet.Server.log")));
36+
// Trace.AutoFlush = true;
37+
3138
config.Routes.MapHttpRoute(
3239
name: "NuGetDefault_ClearCache",
3340
routeTemplate: "nuget/clear-cache",

src/NuGet.Server/App_Start/NuGetODataConfig.cs.pp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System.Net.Http;
22
using System.Web.Http;
3+
using System.Web.Http.ExceptionHandling;
34
using System.Web.Http.Routing;
45
using NuGet.Server;
6+
using NuGet.Server.Infrastructure;
57
using NuGet.Server.V2;
68

79
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof($rootnamespace$.App_Start.NuGetODataConfig), "Start")]
@@ -18,6 +20,11 @@
1820

1921
NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", "PackagesOData");
2022

23+
config.Services.Replace(typeof(IExceptionLogger), new TraceExceptionLogger());
24+
25+
// Trace.Listeners.Add(new TextWriterTraceListener(HostingEnvironment.MapPath("~/NuGet.Server.log")));
26+
// Trace.AutoFlush = true;
27+
2128
config.Routes.MapHttpRoute(
2229
name: "NuGetDefault_ClearCache",
2330
routeTemplate: "nuget/clear-cache",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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.Diagnostics;
5+
using System.Web.Http.ExceptionHandling;
6+
7+
namespace NuGet.Server.Infrastructure
8+
{
9+
public class TraceExceptionLogger : ExceptionLogger
10+
{
11+
public override void Log(ExceptionLoggerContext context)
12+
{
13+
Trace.TraceError(context.ExceptionContext.Exception.ToString());
14+
}
15+
}
16+
}

src/NuGet.Server/NuGet.Server.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<Compile Include="Core\ServiceResolver.cs" />
110110
<Compile Include="Controllers\PackagesODataController.cs" />
111111
<Compile Include="Core\ServiceResolverExtensions.cs" />
112+
<Compile Include="Infrastructure\TraceExceptionLogger.cs" />
112113
<Compile Include="Infrastructure\WebConfigSettingsProvider.cs" />
113114
<Compile Include="Core\Helpers.cs" />
114115
<Compile Include="Infrastructure\PackageAuthenticationService.cs" />

0 commit comments

Comments
 (0)