예제 #1
0
        protected internal virtual ContentSummaryComputationContext ComputeDirectoryContentSummary
            (ContentSummaryComputationContext summary, int snapshotId)
        {
            ReadOnlyList <INode> childrenList = GetChildrenList(snapshotId);

            // Explicit traversing is done to enable repositioning after relinquishing
            // and reacquiring locks.
            for (int i = 0; i < childrenList.Size(); i++)
            {
                INode  child          = childrenList.Get(i);
                byte[] childName      = child.GetLocalNameBytes();
                long   lastYieldCount = summary.GetYieldCount();
                child.ComputeContentSummary(summary);
                // Check whether the computation was paused in the subtree.
                // The counts may be off, but traversing the rest of children
                // should be made safe.
                if (lastYieldCount == summary.GetYieldCount())
                {
                    continue;
                }
                // The locks were released and reacquired. Check parent first.
                if (GetParent() == null)
                {
                    // Stop further counting and return whatever we have so far.
                    break;
                }
                // Obtain the children list again since it may have been modified.
                childrenList = GetChildrenList(snapshotId);
                // Reposition in case the children list is changed. Decrement by 1
                // since it will be incremented when loops.
                i = NextChild(childrenList, childName) - 1;
            }
            // Increment the directory count for this directory.
            summary.GetCounts().AddContent(Content.Directory, 1);
            // Relinquish and reacquire locks if necessary.
            summary.Yield();
            return(summary);
        }