Another way to make sure that the loop terminates is to make sure that it makes progress. Ie, continue only as long as parent_path makes the path shorter.
These checks seem very arbitrary. A user could enter <existing_directory>/a/b/bitcoin, in which case both a and b don't exist yet so there will be "nothing valid" in parentDir.

btw: This is not a "deadlock", but a garden variety infinite loop. Deadlock is a specific situation in which two threads contend for a lock while they hold another one, which is not the case here.