[encryption] infinite loop on sharing

fix infinite loop on sharing a folder where folder and sub-folder has the same name, issue #6875 

cc @PVince81