summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortoonn <toonn@toonn.io>2023-05-31 14:16:27 +0200
committertoonn <toonn@toonn.io>2023-05-31 14:16:27 +0200
commit1a007158cef1279df68d0e8567b126def6b68046 (patch)
treeb9a07537a4933d7b5f8e36996a7b57eb32e5455e
parent5c0cfb088ea345e4ce3c195a6c5a155b84f5d2ba (diff)
parent4fbf8d854b0a7963d22db0e856bed1607f419977 (diff)
Merge branch 'mingmingrr-master'
-rw-r--r--ranger/core/actions.py21
-rw-r--r--ranger/ext/next_available_filename.py22
2 files changed, 10 insertions, 33 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 3f8b3f0d..e1fd2afe 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -32,7 +32,6 @@ from ranger.ext.direction import Direction
from ranger.ext.get_executables import get_executables
from ranger.ext.keybinding_parser import key_to_string, construct_keybinding
from ranger.ext.macrodict import MacroDict, MACRO_FAIL, macro_val
-from ranger.ext.next_available_filename import next_available_filename
from ranger.ext.relative_symlink import relative_symlink
from ranger.ext.rifle import squash_flags, ASK_COMMAND
from ranger.ext.safe_path import get_safe_path
@@ -1567,10 +1566,10 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m
self.do_cut = True
self.ui.browser.main_column.request_redraw()
- def paste_symlink(self, relative=False):
+ def paste_symlink(self, relative=False, make_safe_path=get_safe_path):
copied_files = self.copy_buffer
for fobj in copied_files:
- new_name = next_available_filename(fobj.basename)
+ new_name = make_safe_path(fobj.basename)
self.notify(new_name)
try:
if relative:
@@ -1581,37 +1580,37 @@ class Actions( # pylint: disable=too-many-instance-attributes,too-many-public-m
self.notify('Failed to paste symlink: View log for more info',
bad=True, exception=ex)
- def paste_hardlink(self):
+ def paste_hardlink(self, make_safe_path=get_safe_path):
for fobj in self.copy_buffer:
- new_name = next_available_filename(fobj.basename)
+ new_name = make_safe_path(fobj.basename)
try:
link(fobj.path, join(self.fm.thisdir.path, new_name))
except OSError as ex:
self.notify('Failed to paste hardlink: View log for more info',
bad=True, exception=ex)
- def paste_hardlinked_subtree(self):
+ def paste_hardlinked_subtree(self, make_safe_path=get_safe_path):
for fobj in self.copy_buffer:
try:
target_path = join(self.fm.thisdir.path, fobj.basename)
- self._recurse_hardlinked_tree(fobj.path, target_path)
+ self._recurse_hardlinked_tree(fobj.path, target_path, make_safe_path)
except OSError as ex:
self.notify('Failed to paste hardlinked subtree: View log for more info',
bad=True, exception=ex)
- def _recurse_hardlinked_tree(self, source_path, target_path):
+ def _recurse_hardlinked_tree(self, source_path, target_path, make_safe_path):
if isdir(source_path):
if not exists(target_path):
os.mkdir(target_path, stat(source_path).st_mode)
for item in listdir(source_path):
self._recurse_hardlinked_tree(
join(source_path, item),
- join(target_path, item))
+ join(target_path, item),
+ make_safe_path)
else:
if not exists(target_path) \
or stat(source_path).st_ino != stat(target_path).st_ino:
- link(source_path,
- next_available_filename(target_path))
+ link(source_path, make_safe_path(target_path))
def paste(self, overwrite=False, append=False, dest=None, make_safe_path=get_safe_path):
""":paste
diff --git a/ranger/ext/next_available_filename.py b/ranger/ext/next_available_filename.py
deleted file mode 100644
index 0a5e0856..00000000
--- a/ranger/ext/next_available_filename.py
+++ /dev/null
@@ -1,22 +0,0 @@
-# This file is part of ranger, the console file manager.
-# License: GNU GPL version 3, see the file "AUTHORS" for details.
-
-from __future__ import (absolute_import, division, print_function)
-
-import os.path
-
-
-def next_available_filename(fname, directory="."):
- existing_files = os.listdir(directory)
-
- if fname not in existing_files:
- return fname
- if not fname.endswith("_"):
- fname += "_"
- if fname not in existing_files:
- return fname
-
- for i in range(1, len(existing_files) + 1):
- if fname + str(i) not in existing_files:
- return fname + str(i)
- return None