Fix infinite loop bug in resolve_path