Exemple #1
0
        private bool UpdateFileInformationForAllEntries(MemoryMappedViewAccessor indexView, Index otherIndex, bool shouldAlsoTryPopulateFromDisk)
        {
            long updatedEntriesFromOtherIndex = 0;
            long updatedEntriesFromDisk       = 0;

            using (MemoryMappedFile mmf = otherIndex.GetMemoryMappedFile())
                using (MemoryMappedViewAccessor otherIndexView = mmf.CreateViewAccessor())
                {
                    Parallel.ForEach(
                        this.indexEntryOffsets,
                        entry =>
                    {
                        string currentIndexFilename = entry.Key;
                        long currentIndexOffset     = entry.Value;
                        if (!IndexEntry.HasInitializedCTimeEntry(indexView, currentIndexOffset))
                        {
                            long otherIndexOffset;
                            if (otherIndex.indexEntryOffsets.TryGetValue(currentIndexFilename, out otherIndexOffset))
                            {
                                if (IndexEntry.HasInitializedCTimeEntry(otherIndexView, otherIndexOffset))
                                {
                                    IndexEntry currentIndexEntry = new IndexEntry(indexView, currentIndexOffset);
                                    IndexEntry otherIndexEntry   = new IndexEntry(otherIndexView, otherIndexOffset);

                                    currentIndexEntry.CtimeSeconds            = otherIndexEntry.CtimeSeconds;
                                    currentIndexEntry.CtimeNanosecondFraction = otherIndexEntry.CtimeNanosecondFraction;
                                    currentIndexEntry.MtimeSeconds            = otherIndexEntry.MtimeSeconds;
                                    currentIndexEntry.MtimeNanosecondFraction = otherIndexEntry.MtimeNanosecondFraction;
                                    currentIndexEntry.Size = otherIndexEntry.Size;

                                    Interlocked.Increment(ref updatedEntriesFromOtherIndex);
                                }
                            }
                            else if (shouldAlsoTryPopulateFromDisk)
                            {
                                string localPath = currentIndexFilename.FromGitRelativePathToWindowsFullPath(this.repoRoot);
                                if (TryUpdateEntryFromDisk(indexView, localPath, entry.Value))
                                {
                                    Interlocked.Increment(ref updatedEntriesFromDisk);
                                }
                            }
                        }
                    });
                }

            this.tracer.RelatedEvent(
                EventLevel.Informational,
                "UpdateIndexFileInformation",
                new EventMetadata()
            {
                { "UpdatedFromOtherIndex", updatedEntriesFromOtherIndex },
                { "UpdatedFromDisk", updatedEntriesFromDisk }
            },
                Keywords.Telemetry);

            return((updatedEntriesFromOtherIndex > 0) || (updatedEntriesFromDisk > 0));
        }