Fixes bug when renaming a directory into a subdirectory.

Renaming a directory into a subdiectory fails.
This commit adds a fix and a testcase.