summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2011-10-30 02:23:12 +0200
committerhut <hut@lavabit.com>2011-10-30 02:23:12 +0200
commitec6093297e8851802ff2184cd2949bb9cfbad1d7 (patch)
tree437ceadbcc2bc09209a5d4c65a591a00b818bcaf
parent2081cbe1f64017100ccfccd34a75d7731ff77dae (diff)
downloadranger-ec6093297e8851802ff2184cd2949bb9cfbad1d7.tar.gz
core.actions: paste_symlink() doesn't fail if file exists
-rw-r--r--ranger/core/actions.py10
-rw-r--r--ranger/ext/next_available_filename.py30
2 files changed, 37 insertions, 3 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 5364f391..00fd2179 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -28,6 +28,7 @@ from ranger.ext.direction import Direction
 from ranger.ext.relative_symlink import relative_symlink
 from ranger.ext.keybinding_parser import key_to_string, construct_keybinding
 from ranger.ext.shell_escape import shell_quote
+from ranger.ext.next_available_filename import next_available_filename
 from ranger.core.shared import FileManagerAware, EnvironmentAware, \
 		SettingsAware
 from ranger.fsobject import File
@@ -918,18 +919,21 @@ class Actions(FileManagerAware, EnvironmentAware, SettingsAware):
 	def paste_symlink(self, relative=False):
 		copied_files = self.env.copy
 		for f in copied_files:
+			self.notify(next_available_filename(f.basename))
 			try:
+				new_name = next_available_filename(f.basename)
 				if relative:
-					relative_symlink(f.path, join(getcwd(), f.basename))
+					relative_symlink(f.path, join(getcwd(), new_name))
 				else:
-					symlink(f.path, join(getcwd(), f.basename))
+					symlink(f.path, join(getcwd(), new_name))
 			except Exception as x:
 				self.notify(x)
 
 	def paste_hardlink(self):
 		for f in self.env.copy:
 			try:
-				link(f.path, join(getcwd(), f.basename))
+				new_name = next_available_filename(f.basename)
+				link(f.path, join(getcwd(), new_name))
 			except Exception as x:
 				self.notify(x)
 
diff --git a/ranger/ext/next_available_filename.py b/ranger/ext/next_available_filename.py
new file mode 100644
index 00000000..696063cf
--- /dev/null
+++ b/ranger/ext/next_available_filename.py
@@ -0,0 +1,30 @@
+# Copyright (C) 2011  Roman Zimbelmann <romanz@lavabit.com>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+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)
^
5c210a96 ^

3de15ddd ^

5c210a96 ^
fb275079 ^

5c210a96 ^
3d566884 ^
a1d7ed6e ^
3d566884 ^
621a1a39 ^
9bc5d95c ^
c44b726e ^
465bff73 ^




f027adc0 ^
f8e96a97 ^

0b5c4cbe ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61