Revised r24541 to be hopefully acceptable by the coreutils maintainers.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24550 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -709,9 +709,9 @@ is_empty_dir (int fd_cwd, char const *dir)
|
|||||||
return saved_errno == 0 ? true : false;
|
return saved_errno == 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return -1 if FILE is an unwritable non-symlink,
|
/* Return 1 if FILE is an unwritable non-symlink, 0 if it is writable or some
|
||||||
0 if it is writable or some other type of file,
|
other type of file.
|
||||||
a positive error number if there is some problem in determining the answer.
|
Returns -1 and sets errno if there is some problem in determining the answer.
|
||||||
Set *BUF to the file status.
|
Set *BUF to the file status.
|
||||||
This is to avoid calling euidaccess when FILE is a symlink. */
|
This is to avoid calling euidaccess when FILE is a symlink. */
|
||||||
static int
|
static int
|
||||||
@@ -721,7 +721,7 @@ write_protected_non_symlink (int fd_cwd,
|
|||||||
struct stat *buf)
|
struct stat *buf)
|
||||||
{
|
{
|
||||||
if (cache_fstatat (fd_cwd, file, buf, AT_SYMLINK_NOFOLLOW) != 0)
|
if (cache_fstatat (fd_cwd, file, buf, AT_SYMLINK_NOFOLLOW) != 0)
|
||||||
return errno;
|
return -1;
|
||||||
if (S_ISLNK (buf->st_mode))
|
if (S_ISLNK (buf->st_mode))
|
||||||
return 0;
|
return 0;
|
||||||
/* Here, we know FILE is not a symbolic link. */
|
/* Here, we know FILE is not a symbolic link. */
|
||||||
@@ -778,15 +778,18 @@ write_protected_non_symlink (int fd_cwd,
|
|||||||
= obstack_object_size (&ds->dir_stack) + strlen (file);
|
= obstack_object_size (&ds->dir_stack) + strlen (file);
|
||||||
|
|
||||||
if (MIN (PATH_MAX, 8192) <= file_name_len)
|
if (MIN (PATH_MAX, 8192) <= file_name_len)
|
||||||
return - euidaccess_stat (buf, W_OK);
|
return !euidaccess_stat (buf, W_OK);
|
||||||
if (euidaccess (full_filename (file), W_OK) == 0)
|
if (euidaccess (full_filename (file), W_OK) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if (errno == EACCES)
|
if (errno == EACCES)
|
||||||
return 1;
|
{
|
||||||
|
errno = 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Perhaps some other process has removed the file, or perhaps this
|
/* Perhaps some other process has removed the file, or perhaps this
|
||||||
is a buggy NFS client. */
|
is a buggy NFS client. */
|
||||||
return errno;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,33 +817,34 @@ prompt (int fd_cwd, Dirstack_state const *ds, char const *filename,
|
|||||||
if (x->interactive == RMI_NEVER)
|
if (x->interactive == RMI_NEVER)
|
||||||
return RM_OK;
|
return RM_OK;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
|
||||||
if (!x->ignore_missing_files
|
if (!x->ignore_missing_files
|
||||||
& ((x->interactive == RMI_ALWAYS) | x->stdin_tty))
|
& ((x->interactive == RMI_ALWAYS) | x->stdin_tty))
|
||||||
write_protected = write_protected_non_symlink (fd_cwd, filename, ds, sbuf);
|
write_protected = write_protected_non_symlink (fd_cwd, filename, ds, sbuf);
|
||||||
|
|
||||||
if (write_protected || x->interactive == RMI_ALWAYS)
|
if (write_protected || errno || x->interactive == RMI_ALWAYS)
|
||||||
{
|
{
|
||||||
char const *quoted_name = quote (full_filename (filename));
|
char const *quoted_name = quote (full_filename (filename));
|
||||||
if (write_protected <= 0
|
if (errno == 0)
|
||||||
&& cache_fstatat (fd_cwd, filename, sbuf, AT_SYMLINK_NOFOLLOW) != 0)
|
|
||||||
{
|
{
|
||||||
/* This happens, e.g., with `rm '''. */
|
/* May fail for, e.g., with `rm '''. */
|
||||||
write_protected = errno;
|
cache_fstatat (fd_cwd, filename, sbuf, AT_SYMLINK_NOFOLLOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_protected >= 0)
|
if (errno == 0)
|
||||||
{
|
{
|
||||||
/* Using permissions doesn't make sense for symlinks. */
|
/* Using permissions doesn't make sense for symlinks. */
|
||||||
if (S_ISLNK (sbuf->st_mode) && x->interactive != RMI_ALWAYS)
|
if (S_ISLNK (sbuf->st_mode) && x->interactive != RMI_ALWAYS)
|
||||||
return RM_OK;
|
return RM_OK;
|
||||||
|
|
||||||
if (S_ISDIR (sbuf->st_mode) && !x->recursive)
|
if (S_ISDIR (sbuf->st_mode) && !x->recursive)
|
||||||
write_protected = EISDIR;
|
errno = EISDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_protected < 0)
|
if (errno != 0)
|
||||||
{
|
{
|
||||||
error (0, write_protected, _("cannot remove %s"), quoted_name);
|
error (0, errno, _("cannot remove %s"), quoted_name);
|
||||||
return RM_ERROR;
|
return RM_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user