private bool UpdateFileInformationFromAnotherIndex(Index otherIndex, bool shouldAlsoTryPopulateFromDisk) { long updatedEntriesFromOtherIndex = 0; foreach (KeyValuePair <string, long> i in this.indexEntryOffsets) { string currentIndexFilename = i.Key; long currentIndexOffset = i.Value; if (IndexEntry.HasUninitializedCTimeEntry(this, currentIndexOffset)) { long otherIndexOffset; if (otherIndex.indexEntryOffsets.TryGetValue(currentIndexFilename, out otherIndexOffset)) { if (!IndexEntry.HasUninitializedCTimeEntry(otherIndex, otherIndexOffset)) { IndexEntry currentIndexEntry = new IndexEntry(this, currentIndexOffset); IndexEntry otherIndexEntry = new IndexEntry(otherIndex, otherIndexOffset); currentIndexEntry.CtimeSeconds = otherIndexEntry.CtimeSeconds; currentIndexEntry.CtimeNanosecondFraction = otherIndexEntry.CtimeNanosecondFraction; currentIndexEntry.MtimeSeconds = otherIndexEntry.MtimeSeconds; currentIndexEntry.MtimeNanosecondFraction = otherIndexEntry.MtimeNanosecondFraction; currentIndexEntry.Size = otherIndexEntry.Size; ++updatedEntriesFromOtherIndex; } } } } long updatedEntriesFromDisk = 0; if (shouldAlsoTryPopulateFromDisk) { Parallel.ForEach( this.indexEntryOffsets.Where(entry => IndexEntry.HasUninitializedCTimeEntry(this, entry.Value)), (entry) => { string localPath = entry.Key.FromGitRelativePathToWindowsFullPath(this.repoRoot); UpdateEntryFromDisk(this, localPath, entry.Value, ref updatedEntriesFromDisk); }); this.tracer.RelatedEvent(EventLevel.Informational, "UpdateFileInformationFromAnotherIndex", new EventMetadata() { { "UpdatedFromOtherIndex", updatedEntriesFromOtherIndex }, { "UpdatedFromDisk", updatedEntriesFromDisk } }, Keywords.Telemetry); } this.indexView.Flush(); return((updatedEntriesFromOtherIndex > 0) || (updatedEntriesFromDisk > 0)); }
private bool UpdateFileInformationFromAnotherIndex(Index otherIndex, bool shouldAlsoTryPopulateFromDisk) { long updatedEntriesFromOtherIndex = 0; foreach (KeyValuePair <string, long> i in this.indexEntryOffsets) { string currentIndexFilename = i.Key; long currentIndexOffset = i.Value; if (IndexEntry.HasUninitializedCTimeEntry(this, currentIndexOffset)) { long otherIndexOffset; if (otherIndex.indexEntryOffsets.TryGetValue(currentIndexFilename, out otherIndexOffset)) { if (!IndexEntry.HasUninitializedCTimeEntry(otherIndex, otherIndexOffset)) { IndexEntry currentIndexEntry = new IndexEntry(this, currentIndexOffset); IndexEntry otherIndexEntry = new IndexEntry(otherIndex, otherIndexOffset); currentIndexEntry.CtimeSeconds = otherIndexEntry.CtimeSeconds; currentIndexEntry.CtimeNanosecondFraction = otherIndexEntry.CtimeNanosecondFraction; currentIndexEntry.MtimeSeconds = otherIndexEntry.MtimeSeconds; currentIndexEntry.MtimeNanosecondFraction = otherIndexEntry.MtimeNanosecondFraction; currentIndexEntry.Size = otherIndexEntry.Size; ++updatedEntriesFromOtherIndex; } } } } long updatedEntriesFromDisk = 0; if (shouldAlsoTryPopulateFromDisk) { Parallel.ForEach( this.indexEntryOffsets.Where(entry => IndexEntry.HasUninitializedCTimeEntry(this, entry.Value)), (entry) => { string localPath = entry.Key.FromGitRelativePathToWindowsFullPath(this.repoRoot); try { FileInfo file = new FileInfo(localPath); if (file.Exists) { IndexEntry indexEntry = new IndexEntry(this, entry.Value); indexEntry.Mtime = file.LastWriteTimeUtc; indexEntry.Ctime = file.CreationTimeUtc; indexEntry.Size = (uint)file.Length; System.Threading.Interlocked.Increment(ref updatedEntriesFromDisk); } } catch (System.Security.SecurityException) { // Skip these. } catch (System.UnauthorizedAccessException) { // Skip these. } }); this.tracer.RelatedEvent(EventLevel.Informational, "UpdateFileInformationFromAnotherIndex", new EventMetadata() { { "UpdatedFromOtherIndex", updatedEntriesFromOtherIndex }, { "UpdatedFromDisk", updatedEntriesFromDisk } }); } this.indexView.Flush(); return((updatedEntriesFromOtherIndex > 0) || (updatedEntriesFromDisk > 0)); }