Skip to content

Commit

Permalink
Merge pull request #1345 from zooba/issue-1333
Browse files Browse the repository at this point in the history
Fixes #1333 Error in DB view while analysis DB is changing
  • Loading branch information
zooba committed Jun 16, 2016
2 parents 9ccda66 + dd4cc8a commit f6918d5
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 47 deletions.
Expand Up @@ -174,7 +174,7 @@ bool watchLibraryForChanges
var paths = new List<string>();
paths.Add(databasePath);
if (includeSitePackages) {
paths.AddRange(Directory.EnumerateDirectories(databasePath));
paths.AddRange(PathUtils.EnumerateDirectories(databasePath, recurse: false));
}

try {
Expand Down Expand Up @@ -448,8 +448,7 @@ bool watchLibraryForChanges

private static HashSet<string> GetExistingDatabase(string databasePath) {
return new HashSet<string>(
Directory.EnumerateFiles(databasePath, "*.idb", SearchOption.AllDirectories)
.Select(f => Path.GetFileNameWithoutExtension(f)),
PathUtils.EnumerateFiles(databasePath, "*.idb").Select(f => Path.GetFileNameWithoutExtension(f)),
StringComparer.InvariantCultureIgnoreCase
);
}
Expand Down Expand Up @@ -622,7 +621,7 @@ select groupedByPackage.Key
// Currently we assume that if the file exists, it's up to date.
// PyLibAnalyzer will perform timestamp checks if the user manually
// refreshes.
return Directory.EnumerateFiles(DatabasePath, "*.idb", SearchOption.AllDirectories)
return PathUtils.EnumerateFiles(DatabasePath, "*.idb")
.Select(f => Path.GetFileNameWithoutExtension(f));
}

Expand Down
10 changes: 5 additions & 5 deletions Python/Product/Analysis/ModulePath.cs
Expand Up @@ -151,8 +151,8 @@ bool requireInitPy
}

if (!skipFiles) {
foreach (var file in Directory.EnumerateFiles(path)) {
var filename = Path.GetFileName(file);
foreach (var file in PathUtils.EnumerateFiles(path, recurse: false)) {
var filename = PathUtils.GetFileOrDirectoryName(file);
var match = PythonFileRegex.Match(filename);
if (!match.Success) {
match = PythonBinaryRegex.Match(filename);
Expand All @@ -168,8 +168,8 @@ bool requireInitPy
}

if (recurse) {
foreach (var dir in Directory.EnumerateDirectories(path)) {
var dirname = Path.GetFileName(dir);
foreach (var dir in PathUtils.EnumerateDirectories(path, recurse: false)) {
var dirname = PathUtils.GetFileOrDirectoryName(dir);
var match = PythonPackageRegex.Match(dirname);
if (match.Success && (!requireInitPy || File.Exists(Path.Combine(dir, "__init__.py")))) {
foreach (var entry in GetModuleNamesFromPathHelper(
Expand Down Expand Up @@ -238,7 +238,7 @@ bool requireInitPy
public static IEnumerable<string> ExpandPathFiles(IEnumerable<string> paths) {
foreach (var path in paths) {
if (Directory.Exists(path)) {
foreach (var file in Directory.EnumerateFiles(path, "*.pth")) {
foreach (var file in PathUtils.EnumerateFiles(path, "*.pth", recurse: false)) {
using (var reader = new StreamReader(file)) {
string line;
while ((line = reader.ReadLine()) != null) {
Expand Down
10 changes: 4 additions & 6 deletions Python/Product/Analyzer/PyLibAnalyzer.cs
Expand Up @@ -649,8 +649,8 @@ internal class PyLibAnalyzer : IDisposable {
// If the top level does not contain any .idb files, we won't
// bother recursing.
if (Directory.Exists(_outDir) &&
Directory.EnumerateFiles(_outDir, "*.idb", SearchOption.TopDirectoryOnly).Any()) {
filesInDatabase.UnionWith(Directory.EnumerateFiles(_outDir, "*.idb", SearchOption.AllDirectories));
PathUtils.EnumerateFiles(_outDir, "*.idb", recurse: false).Any()) {
filesInDatabase.UnionWith(PathUtils.EnumerateFiles(_outDir, "*.idb"));
}
} else if (firstRun) {
Directory.CreateDirectory(_outDir);
Expand Down Expand Up @@ -704,7 +704,7 @@ internal class PyLibAnalyzer : IDisposable {
}

if (!_dryRun) {
filesInDatabase.UnionWith(Directory.EnumerateFiles(_outDir, "*.idb", SearchOption.AllDirectories));
filesInDatabase.UnionWith(PathUtils.EnumerateFiles(_outDir, "*.idb"));
}

// Store the files we want to keep separately, in case we decide to
Expand All @@ -728,9 +728,7 @@ internal class PyLibAnalyzer : IDisposable {
} else {
// Failed to get builtin names, so don't delete anything
// from the main output directory.
filesToKeep.UnionWith(
Directory.EnumerateFiles(_outDir, "*.idb", SearchOption.TopDirectoryOnly)
);
filesToKeep.UnionWith(PathUtils.EnumerateFiles(_outDir, "*.idb", recurse: false));
}
}

Expand Down
4 changes: 2 additions & 2 deletions Python/Product/Common/Infrastructure/PathUtils.cs
Expand Up @@ -558,11 +558,11 @@ public static class PathUtils {
}
continue;
}
var result = Directory.EnumerateFiles(dir, file, SearchOption.TopDirectoryOnly).FirstOrDefault();
var result = EnumerateFiles(dir, file, recurse: false).FirstOrDefault();
if (result != null) {
return result;
}
foreach (var subDir in Directory.EnumerateDirectories(dir)) {
foreach (var subDir in EnumerateDirectories(dir, recurse: false)) {
dirQueue.Enqueue(subDir);
}
dirQueue.Enqueue("<EOD>");
Expand Down
2 changes: 1 addition & 1 deletion Python/Product/PythonTools/PythonTools/Project/Conda.cs
Expand Up @@ -44,7 +44,7 @@ IInterpreterRegistryService service

string metaFile;
try {
metaFile = Directory.EnumerateFiles(condaMetaPath, "*.json").FirstOrDefault();
metaFile = PathUtils.EnumerateFiles(condaMetaPath, "*.json", recurse: false).FirstOrDefault();
} catch (Exception ex) {
if (ex.IsCriticalException()) {
throw;
Expand Down
Expand Up @@ -231,13 +231,13 @@ string filters
) {
if (Directory.Exists(sourcePath)) {
return await Task.Run(() => {
var files = Directory.EnumerateFiles(sourcePath, "*.py", SearchOption.TopDirectoryOnly);
var files = PathUtils.EnumerateFiles(sourcePath, "*.py", recurse: false);
// Also include *.pyw files if they were in the filter list
foreach (var pywFilters in filters
.Split(';')
.Where(filter => filter.TrimEnd().EndsWith(".pyw", StringComparison.OrdinalIgnoreCase))
) {
files = files.Concat(Directory.EnumerateFiles(sourcePath, pywFilters, SearchOption.TopDirectoryOnly));
files = files.Concat(PathUtils.EnumerateFiles(sourcePath, pywFilters, recurse: false));
}
return files.Select(f => Path.GetFileName(f)).ToList();
});
Expand Down Expand Up @@ -490,10 +490,7 @@ List<string> virtualEnvPaths
var directories = new List<string>() { source };
var skipDirectories = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

try {
directories.AddRange(Directory.EnumerateDirectories(source, "*", SearchOption.AllDirectories));
} catch (UnauthorizedAccessException) {
}
directories.AddRange(PathUtils.EnumerateDirectories(source));

foreach (var dir in directories) {
if (UnwindDirectory(dir).Any(skipDirectories.Contains)) {
Expand All @@ -511,7 +508,7 @@ List<string> virtualEnvPaths
}

foreach (var filter in patterns) {
files.UnionWith(Directory.EnumerateFiles(dir, filter));
files.UnionWith(PathUtils.EnumerateFiles(dir, filter, recurse: false));
}
} catch (UnauthorizedAccessException) {
}
Expand Down
16 changes: 8 additions & 8 deletions Python/Product/PythonTools/PythonTools/Project/Pip.cs
Expand Up @@ -84,14 +84,14 @@ static class Pip {
var packagesPath = Path.Combine(factory.Configuration.LibraryPath, "site-packages");
HashSet<string> result = null;
if (Directory.Exists(packagesPath)) {
result = await Task.Run(() => new HashSet<string>(Directory.EnumerateDirectories(packagesPath)
.Select(path => Path.GetFileName(path))
.Select(name => PackageNameRegex.Match(name))
.Where(match => match.Success)
.Select(match => match.Groups["name"].Value)
))
.SilenceException<IOException, HashSet<string>>()
.SilenceException<UnauthorizedAccessException, HashSet<string>>()
result = await Task.Run(() => new HashSet<string>(
PathUtils.EnumerateDirectories(packagesPath, recurse: false)
.Select(path => Path.GetFileName(path))
.Select(name => PackageNameRegex.Match(name))
.Where(match => match.Success)
.Select(match => match.Groups["name"].Value)
)
)
.HandleAllExceptions(null, typeof(Pip));
}

Expand Down
Expand Up @@ -1966,14 +1966,10 @@ private static T FindImmediateChild<T>(HierarchyNode parent)
publishOptions = TaskDialog.CallWithRetry(
_ => new PublishProjectOptions(
publishOptions.AdditionalFiles.Concat(
Directory.EnumerateFiles(
factory.Configuration.PrefixPath,
"*",
SearchOption.AllDirectories
)
// Exclude the completion DB
.Where(f => !f.Contains("\\.ptvs\\"))
.Select(f => new PublishFile(f, PathUtils.GetRelativeFilePath(ProjectHome, f)))
PathUtils.EnumerateFiles(factory.Configuration.PrefixPath)
// Exclude the completion DB
.Where(f => !f.Contains("\\.ptvs\\"))
.Select(f => new PublishFile(f, PathUtils.GetRelativeFilePath(ProjectHome, f)))
).ToArray(),
publishOptions.DestinationUrl
),
Expand Down
6 changes: 1 addition & 5 deletions Python/Product/VSInterpreters/DerivedInterpreterFactory.cs
Expand Up @@ -121,11 +121,7 @@ InterpreterFactoryCreationOptions options

var paths = new List<string> { databasePath };
if (includeSitePackages) {
try {
paths.AddRange(Directory.EnumerateDirectories(databasePath));
} catch (IOException) {
} catch (UnauthorizedAccessException) {
}
paths.AddRange(PathUtils.EnumerateDirectories(databasePath));
}
return new PythonTypeDatabase(this, paths, _baseDb);
}
Expand Down
7 changes: 6 additions & 1 deletion Python/Tests/Core/EnvironmentListTests.cs
Expand Up @@ -96,7 +96,12 @@ public class EnvironmentListTests {
Assert.AreEqual(6, environments.Count);
AssertUtil.ContainsExactly(
wpf.Invoke(() => environments.Select(ev => ev.Description).ToList()),
Enumerable.Range(1, 6).Select(i => string.Format("Test Factory {0}", i))
"Test Factory 1 2.7",
"Test Factory 2 3.0",
"Test Factory 3 3.3",
"Test Factory 4 2.7",
"Test Factory 5 3.0",
"Test Factory 6 3.3"
);
}
}
Expand Down

0 comments on commit f6918d5

Please sign in to comment.