예제 #1
0
        private bool IsFileContentsUpToDate(FullPathChanges fullPathChanges, FileData oldFileData)
        {
            Debug.Assert(oldFileData.Contents != null);

            var fullPath = oldFileData.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 (!FileDatabase.IsContainedInSymLinkHelper(_directories, oldFileData.FileName))
                {
                    return(fullPathChanges.GetPathChangeKind(fullPath) == PathChangeKind.None);
                }
            }

            // Do the "expensive" check by going to the file system.
            var fi = _fileSystem.GetFileInfoSnapshot(fullPath);

            return
                ((fi.Exists) &&
                 (fi.IsFile) &&
                 (fi.LastWriteTimeUtc == oldFileData.Contents.UtcLastModified));
        }
예제 #2
0
        private IEnumerable <FileData> GetCommonFiles(FileDatabase oldState)
        {
            if (_files.Count == 0 || oldState.Files.Count == 0)
            {
                return(Enumerable.Empty <FileData>());
            }

            return(oldState.Files.Values.Intersect(_files.Values.Select(x => x.FileData), FileDataComparer.Instance));
        }
예제 #3
0
        /// <summary>
        /// Prepares this instance for searches by computing various snapshots from
        /// the previous <see cref="FileDatabase"/> snapshot and the new current
        /// <see cref="FileSystemTreeSnapshot"/> instance.
        /// </summary>
        private FileDatabase ComputeFileDatabase(FileDatabase previousFileDatabase, FileSystemTreeSnapshot newSnapshot)
        {
            if (previousFileDatabase == null)
            {
                throw new ArgumentNullException("previousFileDatabase");
            }

            if (newSnapshot == null)
            {
                throw new ArgumentNullException("newSnapshot");
            }

            // Compute list of files from tree
            ComputeFileCollection(newSnapshot);

            // Merge old state in new state
            TransferUnchangedFileContents(previousFileDatabase);

            // Load file contents into newState
            ReadMissingFileContents();

            return(CreateFileDatabse());
        }
예제 #4
0
        private void TransferUnchangedFileContents(FileDatabase oldState)
        {
            Logger.Log("Checking for out of date files.");
            var sw = Stopwatch.StartNew();

            IList <FileData> commonOldFiles = GetCommonFiles(oldState).ToArray();

            using (var progress = _progressTrackerFactory.CreateTracker(commonOldFiles.Count)) {
                commonOldFiles
                .AsParallel()
                .Where(oldFileData => {
                    if (progress.Step())
                    {
                        progress.DisplayProgress((i, n) => string.Format("Checking file timestamp {0:n0} of {1:n0}: {2}", i, n, oldFileData.FileName.FullPathName));
                    }
                    return(IsFileContentsUpToDate(oldFileData));
                })
                .ForAll(oldFileData => _files[oldFileData.FileName].FileData.UpdateContents(oldFileData.Contents));
            }

            Logger.Log("Done checking for {0:n0} out of date files in {1:n0} msec.", commonOldFiles.Count,
                       sw.ElapsedMilliseconds);
            Logger.LogMemoryStats();
        }