private FileDatabaseSnapshot CreateFileDatabse(FileSystemEntities entities) { using (new TimeElapsedLogger("Freezing file database state")) { var directories = entities.Directories; // Note: We cannot use "ReferenceEqualityComparer<FileName>" here because // the dictionary will be used in incremental updates where FileName instances // may be new instances from a complete file system enumeration. var files = new Dictionary <FileName, FileWithContents>(entities.Files.Count); var filesWithContentsArray = new FileWithContents[entities.Files.Count]; int filesWithContentsIndex = 0; foreach (var kvp in entities.Files) { var fileData = kvp.Value.FileWithContents; files.Add(kvp.Key, fileData); if (fileData.Contents != null && fileData.Contents.ByteLength > 0) { filesWithContentsArray[filesWithContentsIndex++] = fileData; } } var filesWithContents = new ListSegment <FileWithContents>(filesWithContentsArray, 0, filesWithContentsIndex); var searchableContentsCollection = CreateFilePieces(filesWithContents); FileDatabaseDebugLogger.LogFileContentsStats(filesWithContents); return(new FileDatabaseSnapshot( entities.ProjectHashes, files, files.Keys.ToArray(), directories, searchableContentsCollection, filesWithContents.Count)); } }
private bool IsFileContentsUpToDate(FileSystemEntities entities, FullPathChanges fullPathChanges, FileWithContents existingFileWithContents) { Invariants.Assert(existingFileWithContents.Contents != null); var fullPath = existingFileWithContents.FileName.FullPath; if (fullPathChanges != null) { // We don't get file change events for file in symlinks, so we can't // rely on fullPathChanges contents for our heuristic of avoiding file // system access. // Actually, since we cannot reliable detect changes in symlinks, we enable this // optimization anyways, as we rely on the user to manually refresh the index // (that results in a "null" value for fullPathChanges) //if (!FileDatabaseSnapshot.IsContainedInSymLinkHelper(entities.Directories, existingFileWithContents.FileName)) { return(fullPathChanges.ShouldSkipLoadFileContents(fullPath)); //} } // Do the "expensive" check by going to the file system. var fi = _fileSystem.GetFileInfoSnapshot(fullPath); return ((fi.Exists) && (fi.IsFile) && (fi.LastWriteTimeUtc == existingFileWithContents.Contents.UtcLastModified)); }
/// <summary> /// Create chunks of 100KB for files larger than 100KB. /// </summary> private static IEnumerable <FileContentsPiece> SplitFileContents(FileWithContents fileWithContents, int fileId) { var range = fileWithContents.Contents.TextRange; while (range.Length > 0) { // TODO(rpaquay): Be smarter and split around new lines characters. var chunkLength = Math.Min(range.Length, ChunkSize); var chunk = new TextRange(range.Position, chunkLength); yield return(fileWithContents.Contents.CreatePiece(fileWithContents.FileName, fileId, chunk)); range = new TextRange(chunk.EndPosition, range.EndPosition - chunk.EndPosition); } }
public ProjectFileData(IProject project, FileWithContents fileWithContents) { _project = project; _fileWithContents = fileWithContents; }
private bool IsFileContentsUpToDate(FileSystemEntities entities, FullPathChanges fullPathChanges, FileWithContents existingFileWithContents) { Debug.Assert(existingFileWithContents.Contents != null); var fullPath = existingFileWithContents.FileName.FullPath; if (fullPathChanges != null) { // We don't get file change events for file in symlinks, so we can't // rely on fullPathChanges contents for our heuristic of avoiding file // system access. if (!FileDatabaseSnapshot.IsContainedInSymLinkHelper(entities.Directories, existingFileWithContents.FileName)) { return(fullPathChanges.ShouldSkipLoadFileContents(fullPath)); } } // Do the "expensive" check by going to the file system. var fi = _fileSystem.GetFileInfoSnapshot(fullPath); return ((fi.Exists) && (fi.IsFile) && (fi.LastWriteTimeUtc == existingFileWithContents.Contents.UtcLastModified)); }
public static bool FileHasContents(FileWithContents x) { return(x.HasContents()); }