summaryrefslogtreecommitdiff
path: root/src/remove.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-07-25 15:27:55 +0000
committerJim Meyering <jim@meyering.net>1998-07-25 15:27:55 +0000
commitd04604664a580f2805fe4111592467bb656d71f6 (patch)
treef564e56a097aedd978165bdb09c310934521c6e5 /src/remove.c
parent4e9a99dd9a9ffc5a2a2dc17c55fc5b58f0cafa02 (diff)
downloadcoreutils-d04604664a580f2805fe4111592467bb656d71f6.tar.xz
(same_file): New function
(remove_dir): Use it to give a better diagnostic when rmdir fails because it can't remove the current directory.
Diffstat (limited to 'src/remove.c')
-rw-r--r--src/remove.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/remove.c b/src/remove.c
index 6d5a61b33..995e93185 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -412,6 +412,16 @@ fspec_filetype_mode (const struct File_spec *fs)
return fs->mode;
}
+static int
+same_file (const char *file_1, const char *file_2)
+{
+ struct stat sb1, sb2;
+ return (lstat (file_1, &sb1) == 0
+ && lstat (file_2, &sb2) == 0
+ && SAME_INODE (sb1, sb2));
+}
+
+
/* Recursively remove all of the entries in the current directory.
Return an indication of the success of the operation. */
@@ -735,8 +745,24 @@ remove_dir (struct File_spec *fs, int need_save_cwd, const struct rm_options *x)
if (rmdir (dir_name) && (errno != ENOENT || !x->ignore_missing_files))
{
- error (0, errno, _("cannot remove directory `%s'"),
- full_filename (dir_name));
+ int saved_errno = errno;
+
+#ifndef EINVAL
+# define EINVAL 0
+#endif
+ /* See if rmdir just failed because DIR_NAME is the current directory.
+ If so, give a better diagnostic than `rm: cannot remove directory
+ `...': Invalid argument' */
+ if (errno == EINVAL && same_file (".", dir_name))
+ {
+ error (0, 0, _("cannot remove current directory `%s'"),
+ full_filename (dir_name));
+ }
+ else
+ {
+ error (0, saved_errno, _("cannot remove directory `%s'"),
+ full_filename (dir_name));
+ }
return RM_ERROR;
}