Skip to content

Commit

Permalink
Shorten logging when skipping directories
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaquay committed Jun 12, 2020
1 parent b2b493d commit bc5ecc6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
14 changes: 11 additions & 3 deletions src/Core/Chromium/ChromiumDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

using System;
using System.Collections.Generic;
using System.Linq;
using VsChromium.Core.Configuration;
using VsChromium.Core.Files;
using VsChromium.Core.Files.PatternMatching;
using VsChromium.Core.Logging;
using VsChromium.Core.Win32.Files;

namespace VsChromium.Core.Chromium {
Expand Down Expand Up @@ -37,9 +39,15 @@ private bool IsChromiumSourceDirectory(FullPath path, IFilePatternsPathMatcherPr
}

// We need to ensure that all pattern lines are covered by at least one file/directory of |path|.
var entries = _fileSystem.GetDirectoryEntries(path);
return chromiumEnlistmentFilePatterns.PathMatcherEntries
.All(item => MatchFileOrDirectory(item, entries));
try {
var entries = _fileSystem.GetDirectoryEntries(path);
return chromiumEnlistmentFilePatterns.PathMatcherEntries
.All(item => MatchFileOrDirectory(item, entries));
}
catch (Exception e) {
Logger.LogWarn(e, "Error detecting chromium root directory, skipping directory \"{0}\"", path);
return false;
}
}

private static bool MatchFileOrDirectory(IPathMatcher item, IList<DirectoryEntry> entries) {
Expand Down
11 changes: 2 additions & 9 deletions src/Core/Win32/Files/NativeFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,8 @@ public static unsafe List<DirectoryEntry> GetDirectoryEntries(string path) {
IntPtr.Zero);
if (fileHandle.IsInvalid) {
var lastWin32Error = Marshal.GetLastWin32Error();
if (lastWin32Error != (int)Win32Errors.ERROR_FILE_NOT_FOUND &&
lastWin32Error != (int)Win32Errors.ERROR_PATH_NOT_FOUND &&
lastWin32Error != (int)Win32Errors.ERROR_ACCESS_DENIED) {
throw new LastWin32ErrorException(lastWin32Error,
string.Format("Error enumerating files at \"{0}\".", path));
}

// Skip this directory
return directoryEntries;
throw new LastWin32ErrorException(lastWin32Error,
string.Format("Error enumerating files at \"{0}\".", path));
}

using (fileHandle) {
Expand Down
10 changes: 8 additions & 2 deletions src/Server/FileSystem/Builder/ProjectRootSnapshotBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -289,11 +290,16 @@ private List<Task> ProcessDirectory(DirectoryData directory, ConcurrentBag<Direc
}

private IList<DirectoryEntry> GetDirectoryEntries(DirectoryData directory) {
var path = _project.RootPath.Combine(directory.DirectoryName.RelativePath);
try {
return _fileSystem.GetDirectoryEntries(_project.RootPath.Combine(directory.DirectoryName.RelativePath));
return _fileSystem.GetDirectoryEntries(path);
}
catch (Win32Exception e) {
Logger.LogWarn("Skipping directory \"{0}\": {1} ({2})", path, e.Message, e.NativeErrorCode);
return ArrayUtilities.EmptyList<DirectoryEntry>.Instance;
}
catch (Exception e) {
Logger.LogWarn(e, "Skipping directory due to error");
Logger.LogWarn(e, "Skipping directory \"{0}\"", path);
return ArrayUtilities.EmptyList<DirectoryEntry>.Instance;
}
}
Expand Down

0 comments on commit bc5ecc6

Please sign in to comment.