[stable5] Make getPath work for shared files

Backport of #7935

cc @PVince81 @DeepDiver1975