Skip to content

Commit 245d245

Browse files
committed
Symbolic link behavior change
* Don't disable file change detection optimization for files inside symbolic link directories. This is unreliable anyways.
1 parent 3544942 commit 245d245

File tree

1 file changed

+47
-36
lines changed

1 file changed

+47
-36
lines changed

src/Server/FileSystemDatabase/Builder/FileDatabaseBuilder.cs

+47-36
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ public FileDatabaseBuilder(
4040
_progressTrackerFactory = progressTrackerFactory;
4141
}
4242

43-
public IFileDatabaseSnapshot Build(IFileDatabaseSnapshot previousDatabase, FileSystemSnapshot newSnapshot,
44-
FullPathChanges fullPathChanges,
45-
Action onLoading, Action onLoaded, Action<IFileDatabaseSnapshot> onIntermadiateResult,
46-
CancellationToken cancellationToken) {
43+
public IFileDatabaseSnapshot Build(IFileDatabaseSnapshot previousDatabase,
44+
FileSystemSnapshot newSnapshot,
45+
FullPathChanges fullPathChanges,
46+
Action onLoading,
47+
Action onLoaded,
48+
Action<IFileDatabaseSnapshot> onIntermadiateResult,
49+
CancellationToken cancellationToken) {
4750
using (new TimeElapsedLogger("Building file database from previous one and file system tree snapshot",
4851
cancellationToken, InfoLogger.Instance)) {
4952
using (var progress = _progressTrackerFactory.CreateIndeterminateTracker()) {
@@ -94,10 +97,12 @@ public IFileDatabaseSnapshot Build(IFileDatabaseSnapshot previousDatabase, FileS
9497
}
9598

9699
public IFileDatabaseSnapshot BuildWithChangedFiles(IFileDatabaseSnapshot previousFileDatabaseSnapshot,
97-
FileSystemSnapshot fileSystemSnapshot, IEnumerable<ProjectFileName> changedFiles,
98-
Action onLoading, Action onLoaded, Action<IFileDatabaseSnapshot> onIntermadiateResult,
99-
CancellationToken cancellationToken) {
100-
100+
FileSystemSnapshot fileSystemSnapshot,
101+
IEnumerable<ProjectFileName> changedFiles,
102+
Action onLoading,
103+
Action onLoaded,
104+
Action<IFileDatabaseSnapshot> onIntermadiateResult,
105+
CancellationToken cancellationToken) {
101106
using (new TimeElapsedLogger("Building file database from previous one and list of changed files",
102107
cancellationToken, InfoLogger.Instance)) {
103108
Invariants.Assert(previousFileDatabaseSnapshot is FileDatabaseSnapshot);
@@ -129,8 +134,9 @@ public IFileDatabaseSnapshot BuildWithChangedFiles(IFileDatabaseSnapshot previou
129134
}
130135
}
131136

132-
private FileDatabaseSnapshot CreateFileDatabase(FileSystemEntities entities, bool notifyProgress,
133-
CancellationToken cancellationToken) {
137+
private FileDatabaseSnapshot CreateFileDatabase(FileSystemEntities entities,
138+
bool notifyProgress,
139+
CancellationToken cancellationToken) {
134140
cancellationToken.ThrowIfCancellationRequested();
135141
using (new TimeElapsedLogger("Freezing file database state", cancellationToken)) {
136142
var progress = notifyProgress ? _progressTrackerFactory.CreateIndeterminateTracker() : null;
@@ -250,7 +256,7 @@ private class FileSystemEntities {
250256
}
251257

252258
private FileSystemEntities ComputeFileSystemEntities(FileSystemSnapshot snapshot,
253-
CancellationToken cancellationToken) {
259+
CancellationToken cancellationToken) {
254260
using (new TimeElapsedLogger("Computing tables of directory names and file names from FileSystemTree",
255261
cancellationToken)) {
256262

@@ -312,8 +318,9 @@ private class FileContentsLoadingContext {
312318
public PartialProgressReporter PartialProgressReporter;
313319
}
314320

315-
private void LoadFileContents(FileSystemEntities entities, FileContentsLoadingContext loadingContext,
316-
CancellationToken cancellationToken) {
321+
private void LoadFileContents(FileSystemEntities entities,
322+
FileContentsLoadingContext loadingContext,
323+
CancellationToken cancellationToken) {
317324
using (new TimeElapsedLogger("Loading file contents from disk", cancellationToken)) {
318325
using (var progress = _progressTrackerFactory.CreateTracker(entities.Files.Count)) {
319326
entities.Files.AsParallelWrapper().ForAll(fileEntry => {
@@ -358,7 +365,8 @@ private void LoadFileContents(FileSystemEntities entities, FileContentsLoadingCo
358365
/// and <see cref="SlimHashTable{TKey,TValue}"/> behave that way.</para>
359366
/// </summary>
360367
private static void DangerousUpdateFileSystemEntitiesEntry(FileSystemEntities entities,
361-
KeyValuePair<FileName, ProjectFileData> fileEntry, FileContents contents) {
368+
KeyValuePair<FileName, ProjectFileData> fileEntry,
369+
FileContents contents) {
362370
entities.Files[fileEntry.Key] = fileEntry.Value.WithContents(contents);
363371
}
364372

@@ -374,21 +382,21 @@ private static void DangerousUpdateFileSystemEntitiesEntry(FileSystemEntities en
374382
/// 2) is verified because the two possible implementations, <see cref="Dictionary{TKey,TValue}"/>
375383
/// and <see cref="SlimHashTable{TKey,TValue}"/> behave that way.</para>
376384
/// </summary>
377-
private static void DangerousUpdateFileTableEntry(FileDatabaseSnapshot fileDatabase, FileName fileName,
378-
FileContents newContents) {
385+
private static void DangerousUpdateFileTableEntry(FileDatabaseSnapshot fileDatabase,
386+
FileName fileName,
387+
FileContents newContents) {
379388
fileDatabase.Files[fileName] = new FileWithContents(fileName, newContents);
380389
}
381390

382-
private FileContents LoadSingleFileContents(
383-
FileSystemEntities entities,
384-
FileContentsLoadingContext loadingContext,
385-
ProjectFileData projectFileData) {
386-
391+
private FileContents LoadSingleFileContents(FileSystemEntities entities,
392+
FileContentsLoadingContext loadingContext,
393+
ProjectFileData projectFileData) {
387394
var fileName = projectFileData.FileName;
388-
var oldFileData = loadingContext.OldFileDatabaseSnapshot.Files.GetValueType(fileName);
395+
var file = loadingContext.OldFileDatabaseSnapshot.Files.GetValueType(fileName);
389396

390-
// If the file was never loaded before, just load it
391-
if (oldFileData == null || oldFileData.Value.Contents == null) {
397+
// If the file was never loaded before, just load it (after performing a
398+
// "isSearchable" check).
399+
if (file?.Contents == null) {
392400
return LoadSingleFileContentsWorker(loadingContext, projectFileData);
393401
}
394402

@@ -413,17 +421,15 @@ private FileContents LoadSingleFileContents(
413421

414422
// If the file has not changed since the previous snapshot, we can re-use
415423
// the former file contents snapshot.
416-
if (IsFileContentsUpToDate(entities, loadingContext.FullPathChanges, oldFileData.Value)) {
417-
return oldFileData.Value.Contents;
424+
if (IsFileContentsUpToDate(entities, loadingContext.FullPathChanges, file.Value)) {
425+
return file.Value.Contents;
418426
}
419427

420428
return LoadSingleFileContentsWorker(loadingContext, projectFileData);
421429
}
422430

423-
private FileContents LoadSingleFileContentsWorker(
424-
FileContentsLoadingContext loadingContext,
425-
ProjectFileData projectFileData) {
426-
431+
private FileContents LoadSingleFileContentsWorker(FileContentsLoadingContext loadingContext,
432+
ProjectFileData projectFileData) {
427433
// If project configuration has not changed, the file is still not
428434
// searchable, irrelevant to calling "IsSearchable".
429435
if (loadingContext.FullPathChanges != null) {
@@ -434,8 +440,9 @@ private FileContents LoadSingleFileContentsWorker(
434440
}
435441

436442
// This is an expensive call, hopefully avoided by the code above.
437-
if (!projectFileData.IsSearchable)
443+
if (!projectFileData.IsSearchable) {
438444
return null;
445+
}
439446

440447
loadingContext.PartialProgressReporter.ReportProgress();
441448

@@ -449,8 +456,9 @@ private FileContents LoadSingleFileContentsWorker(
449456
return fileContents;
450457
}
451458

452-
private bool IsFileContentsUpToDate(FileSystemEntities entities, FullPathChanges fullPathChanges,
453-
FileWithContents existingFileWithContents) {
459+
private bool IsFileContentsUpToDate(FileSystemEntities entities,
460+
FullPathChanges fullPathChanges,
461+
FileWithContents existingFileWithContents) {
454462
Invariants.Assert(existingFileWithContents.Contents != null);
455463

456464
var fullPath = existingFileWithContents.FileName.FullPath;
@@ -459,9 +467,12 @@ private bool IsFileContentsUpToDate(FileSystemEntities entities, FullPathChanges
459467
// We don't get file change events for file in symlinks, so we can't
460468
// rely on fullPathChanges contents for our heuristic of avoiding file
461469
// system access.
462-
if (!FileDatabaseSnapshot.IsContainedInSymLinkHelper(entities.Directories, existingFileWithContents.FileName)) {
463-
return fullPathChanges.ShouldSkipLoadFileContents(fullPath);
464-
}
470+
// Actually, since we cannot reliable detect changes in symlinks, we enable this
471+
// optimization anyways, as we rely on the user to manually refresh the index
472+
// (that results in a "null" value for fullPathChanges)
473+
//if (!FileDatabaseSnapshot.IsContainedInSymLinkHelper(entities.Directories, existingFileWithContents.FileName)) {
474+
return fullPathChanges.ShouldSkipLoadFileContents(fullPath);
475+
//}
465476
}
466477

467478
// Do the "expensive" check by going to the file system.

0 commit comments

Comments
 (0)