1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-11 14:44:18 +02:00

(same_file): New function

(remove_dir): Use it to give a better diagnostic when rmdir fails
because it can't remove the current directory.
This commit is contained in:
Jim Meyering
1998-07-25 15:27:55 +00:00
parent 4e9a99dd9a
commit d04604664a

View File

@@ -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;
}