le sam 23-11-2002 � 23:12, Ga�l Le Mignot a �crit :
> It's a known bug, when using "rm foo/" rm contacts the node foo and asks it
> to remove "./" which, of course, doesn't work. When you use "rm foo" rm
> contacts . and asks it to remove "./foo" which can work. Well, at least it's
> what I understood.
>
> I'm not sure where the fix should be (in libc ? in the program rm ?)
As rm doesn't delete the '/', it is a rm bug.
The patch sent with this mail corrects this bug [for me].
In fact, there was in rm.c this function :
<<
void strip_trailing_slashes ();
>>
As it didn't do anything, the '/' was not deleted. I just implemented
this function.
But maybe some work could be done in etx2fs.
In "ext2fs/dir.c", the function "diskfs_lookup_hard" should understand a
search for "/" and return a good descriptor, so that
"diskfs_dirremove_hard" can happily remove it.
olivier
diff -urN fileutils-4.1.old/src/rm.c fileutils-4.1/src/rm.c
--- fileutils-4.1.old/src/rm.c Sun Nov 24 15:46:40 2002
+++ fileutils-4.1/src/rm.c Sun Nov 24 15:46:07 2002
@@ -60,7 +60,21 @@
#define AUTHORS \
"Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering"
-void strip_trailing_slashes ();
+char *
+strip_trailing_slashes (char * name) {
+ int origlen = sizeof (name);
+ int newlen = origlen;
+ while ((name [newlen-1] == '/')
+ || ((name [newlen-1] == '.') && (name [newlen-2] == '/'))) {
+ if (name [newlen-1] == '.')
+ newlen--;
+ newlen--;
+ }
+ if (newlen != origlen) {
+ name [newlen] = '\0'
+ }
+ return name;
+}
/* Name this program was run with. */
char *program_name;
@@ -131,6 +145,7 @@
struct rm_options x;
int fail = 0;
int c;
+ char * name;
program_name = argv[0];
setlocale (LC_ALL, "");
@@ -192,12 +207,16 @@
/* Stripping slashes is harmless for rmdir;
if the arg is not a directory, it will fail with ENOTDIR. */
- strip_trailing_slashes (argv[optind]);
- fspec_init_file (&fs, argv[optind]);
- status = rm (&fs, 1, &x);
- assert (VALID_STATUS (status));
- if (status == RM_ERROR)
- fail = 1;
+ name = strip_trailing_slashes (argv[optind]);
+ if (name == NULL)
+ fail = 1;
+ else {
+ fspec_init_file (&fs, name);
+ status = rm (&fs, 1, &x);
+ assert (VALID_STATUS (status));
+ if (status == RM_ERROR)
+ fail = 1;
+ }
}
remove_fini ();