2
Vote

ProjectNode.WalkSourceProjectAndAdd() contains bug

description

Problem Description: WalkSourceProjectAndAdd() method of ProjectNode class contains 2 errors. The bug appears in Drag'n'Drop operations. When I drag and drop folder which contains several file nodes it tries to create the same file several times.
 

Your code:

if (addSiblings)
{
// Then look at siblings
currentItemID = itemId;
while (currentItemID != VSConstants.VSITEMID_NIL)
{
variant = null;
ErrorHandler.ThrowOnFailure(sourceHierarchy.GetProperty(itemId, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out variant));
currentItemID = (uint)(int)variant;
WalkSourceProjectAndAdd(sourceHierarchy, currentItemID, targetNode, true);
}

}

 

I've changed the code this way:

....
variant = null;
ErrorHandler.ThrowOnFailure(sourceHierarchy.GetProperty(currentItemID, (int)__VSHPROPID.VSHPROPID_NextVisibleSibling, out variant));
currentItemID = (uint)(int)variant;
WalkSourceProjectAndAdd(sourceHierarchy, currentItemID, targetNode, false);

.....

 
First of all you need to invoke GetProperty() with currentItemID parameter and second WalkSourceProjectAndAdd() should be called with addSibling=false.
Otherwise it enumerates sibling nodes in wrong way and calls this method several times for the same node.
 
 
Repro Steps:
Drag'n'Drop folder containing 2 file nodes.
 
Actual Results:
ApplicationException is risen in ProjectNode.AddNodeIfTargetExistInStorage() method.
 
Expected Results:
Drag'n'Drop works fine.

comments