On Thu, 02 Feb 2023 12:55:23 +0800
Ziyao <zi...@disroot.org> wrote:

> Hi list,
> 
> The applet rm fails to remove an empty directoy without read permission 
> and
> just exits silently.
> 
> For example,
> $ mkdir t && chmod 100 t
> $ rm -rf t                 # Print nothing and the directory is still 
> there
> $ echo $?
> 1
> 
> This problem does not exist in GNU coreutils.

Hi,
But Posix says:

If file is of type directory, the following steps shall be taken:

    If neither the -R option nor the -r option is specified, rm shall write a 
diagnostic 
    message to standard error, do nothing more with file, and go on to any 
remaining files.

    If the -f option is not specified, and either the permissions of file do 
not permit writing
   and the standard input is a terminal or the -i option is specified, rm shall 
write
   a prompt to standard error and read a line from the standard input. 
   If the response is not affirmative, rm shall do nothing more with the 
current file and go on to any remaining files.

so my question is: does your patch remove the dir only with -rf options
or with all option combinations?

Ciao,
Tito

> 
> rm invokes remove_file() to do the actual remove, which tries to open it
> first when removing a directory (libbb/remove_file.c:49). I guess it is 
> for
> removing its contents because we cannot remove a nonempty directory.
> But if reading the directory is not permitted, opendir() will fail and 
> cause
> rm exiting without an error message.
> 
> This small patch tries to remove the directory first instead of opening 
> it,
> and prints a friendly message when the opening fails instead of exiting
> silently.
> 
> ----
> diff --git a/libbb/remove_file.c b/libbb/remove_file.c
> index 1505e62..7bee9f0 100644
> --- a/libbb/remove_file.c
> +++ b/libbb/remove_file.c
> @@ -45,8 +45,15 @@ int FAST_FUNC remove_file(const char *path, int 
> flags)
>                                  return 0;
>                  }
> 
> +               /*
> +                *      Handle empty directoires even if without read 
> permission
> +                */
> +               if (!rmdir(path))
> +                       return 0;
> +
>                  dp = opendir(path);
> -               if (dp == NULL) {
> +               if (!dp) {
> +                       bb_perror_msg("can't remove '%s'",path);
>                          return -1;
>                  }
> 
> 

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to