change the semantics of duplication

Merged Harald Sitter requested to merge work/sitter/backportfixies into release/22.12

previously this would simply clone the shared pointer, but that leaves references into the old tree behind which can then cause state confusion (e.g. the asserts to do with m_parent consistency can fail). instead opt for a deep-clone behavior. it's more expensive but also much much safer.

code is very exhaustive because we don't want to stack exhaust on duplication so a recursive call won't do. instead we iterate down the tree and then append all folders in reverse order.

add a test to ensure duplication works correctly

BUG: 463442

Merge request reports