Skip to contentSkip to conversation

rename: allow full-path renames

PATCH Superseded Andreas Henriksson 3 participants 8 messages Jun 22, 2015 – Jun 25, 2015 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rename: allow full-path renames

From: Andreas Henriksson <[email protected]>

The command "touch b0;rename.ul -v ./b0 ./b1 ./b0" used to work before "allow renaming in subdirectories" change. (regression in commit bd9ced628bb86)

Addresses: https://bugs.debian.org/789240

---
 misc-utils/rename.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
misc-utils/rename.c +3 -2
index 7ac068d..c8a4f8c 100644
@@ -92,10 +92,11 @@ static int do_symlink(char *from, char *to, char *s, int verbose)
 
 static int do_file(char *from, char *to, char *s, int verbose)
 {
-	char *newname = NULL, *file;
+	char *newname = NULL, *file=NULL;
 	int ret = 1;
 
-	file = strrchr(s, '/');
+	if (strchr(from, '/') == NULL && strchr(to, '/') == NULL)
+		file = strrchr(s, '/');
 	if (file == NULL)
 		file = s;
 	if (string_replace(from, to, file, s, &newname))
Signature · 4 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
#1 lore raw
Quoted 7 lines · Andreas Henriksson

The command "touch b0;rename.ul -v ./b0 ./b1 ./b0" used to work before "allow renaming in subdirectories" change. (regression in commit bd9ced628bb86)

Addresses: https://bugs.debian.org/789240

Hi Andreas,

Change looks good, but I would add a test to avoid same regression happening in future. The same change with test can be found from my git.

https://github.com/kerolasa/lelux-utiliteetit/commit/19ef4954935c65559e7561b4b3becbe462848127

Signature · 4 lines
Sami Kerola
http://www.iki.fi/kerolasa/
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
#2 lore raw

PATCH 1/1 tests: add fullpath tests to rename/subdir

---
 tests/expected/rename/subdir |  9 +++++++++
 tests/ts/rename/subdir       | 24 ++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
tests/expected/rename/subdir +9 -0
index a5b3dbe..f429602 100644
@@ -18,3 +18,12 @@ renxme/aa
 renxme/aa
 renxme/aa
 renxme/aa
+== fullpath ==
+`./rename_path1' -> `./rename_path2'
+./rename_path2
+`rename_path_test1' -> `rename_path_a/test1'
+./rename_path_a/test1
+`rename_path_a/test2' -> `rename_path_b/test2'
+rename_path_a
+rename_path_b
+rename_path_b/test2
tests/ts/rename/subdir +24 -0
index 4ae7005..01472fa 100755
@@ -41,4 +41,28 @@ done
 
 rm -rf rename_a{a,b}
 
+echo "== fullpath ==" >> $TS_OUTPUT
+touch rename_path1
+$TS_CMD_RENAME -v ./rename_path1 ./rename_path2 ./rename_path1 >> $TS_OUTPUT 2>&1
+
+find . -name 'rename_path*' >> $TS_OUTPUT 2>&1
+rm -f ./rename_path*
+
+mkdir rename_path_a
+touch rename_path_test1
+
+$TS_CMD_RENAME -v rename_path_test1 rename_path_a/test1 rename_path_test1 >> $TS_OUTPUT 2>&1
+
+find . -name '*test1*' >> $TS_OUTPUT 2>&1
+rm -f rename_path_test1 rename_path_a/test1
+
+mkdir rename_path_b
+touch rename_path_a/test2
+$TS_CMD_RENAME -v rename_path_a/test2 rename_path_b/test2 rename_path_a/test2 >> $TS_OUTPUT 2>&1
+
+find rename_path_a rename_path_b >> $TS_OUTPUT 2>&1
+rm -f rename_path_a/test2 rename_path_b/test2
+
+rmdir rename_path_a rename_path_b
+
 ts_finalize
Signature · 4 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
maintainer Applied
#3 lore raw

Re: [PATCH] tests: add fullpath tests to rename/subdir

Quoted 3 lines · Andreas Henriksson
 tests/expected/rename/subdir |  9 +++++++++
 tests/ts/rename/subdir       | 24 ++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#4 lore raw

PATCH v2 1/1 rename: allow full-path renames

In reply to Sami Kerola

The command "touch b0;rename.ul -v ./b0 ./b1 ./b0" used to work before "allow renaming in subdirectories" change. (regression in commit bd9ced628bb86)

Addresses: https://bugs.debian.org/789240

---
 misc-utils/rename.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

v2: fixed my email address, add reviewed by.

misc-utils/rename.c +3 -2
index 7ac068d..c8a4f8c 100644
@@ -92,10 +92,11 @@ static int do_symlink(char *from, char *to, char *s, int verbose)
 
 static int do_file(char *from, char *to, char *s, int verbose)
 {
-	char *newname = NULL, *file;
+	char *newname = NULL, *file=NULL;
 	int ret = 1;
 
-	file = strrchr(s, '/');
+	if (strchr(from, '/') == NULL && strchr(to, '/') == NULL)
+		file = strrchr(s, '/');
 	if (file == NULL)
 		file = s;
 	if (string_replace(from, to, file, s, &newname))
Signature · 4 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
maintainer Applied
#5 lore raw
Quoted 2 lines · Andreas Henriksson
 misc-utils/rename.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#6 lore raw
In reply to Sami Kerola

Hello Sami Kerola.

Quoted 5 lines · Sami Kerola

Hi Andreas,

Change looks good, but I would add a test to avoid same regression happening in future. The same change with test can be found from my git.

Thanks for your quick review. I was just about to send out the tests I was writing which should now be in your inbox with hopefully a bit more coverage...

Also submitted patch v2 with your Reviewed-by added.

Regards,
Andreas Henriksson
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in

maintainer
#7 lore raw
In reply to Sami Kerola
Quoted 5 lines · Sami Kerola

Change looks good, but I would add a test to avoid same regression happening in future. The same change with test can be found from my git.

https://github.com/kerolasa/lelux-utiliteetit/commit/19ef4954935c65559e7561b4b3becbe462848127

I have applied Andreas' test (but if you want to submit more tests then go ahead :-)

Please, keep tests in the independent commits.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com