diff options
Diffstat (limited to 'ranger/ext/safe_path.py')
-rw-r--r-- | ranger/ext/safe_path.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/ranger/ext/safe_path.py b/ranger/ext/safe_path.py new file mode 100644 index 00000000..ed2cf2b6 --- /dev/null +++ b/ranger/ext/safe_path.py @@ -0,0 +1,22 @@ +# This file is part of ranger, the console file manager. +# License: GNU GPL version 3, see the file "AUTHORS" for details. + +import os + +APPENDIX = '_' + + +def get_safe_path(dst): + if not os.path.exists(dst): + return dst + if not dst.endswith(APPENDIX): + dst += APPENDIX + if not os.path.exists(dst): + return dst + n = 0 + test_dst = dst + str(n) + while os.path.exists(test_dst): + n += 1 + test_dst = dst + str(n) + + return test_dst |