[PATCH] Fix failure to remove an empty directory without read permission
Ziyao
ziyao at disroot.org
Fri Feb 3 03:21:16 UTC 2023
On 2023-02-02 15:14, tito wrote:
> On Thu, 02 Feb 2023 12:55:23 +0800
> 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
Sorry, my last mail was sent to Tito only.
The patch only removes the directory with -r specified. However, it does
not give an additional prompt when -i is specified.
Maybe the following patch is better.
---
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index 1505e62..7b60ab3 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -46,8 +46,8 @@ int FAST_FUNC remove_file(const char *path, int flags)
}
dp = opendir(path);
- if (dp == NULL) {
- return -1;
+ if (!dp) {
+ goto tryRemoveDir;
}
while ((d = readdir(dp)) != NULL) {
@@ -62,7 +62,8 @@ int FAST_FUNC remove_file(const char *path, int flags)
}
closedir(dp);
- if (flags & FILEUTILS_INTERACTIVE) {
+tryRemoveDir:
+ if ((flags & FILEUTILS_INTERACTIVE)) {
fprintf(stderr, "%s: remove directory '%s'? ",
applet_name, path);
if (!bb_ask_y_confirmation())
--
Ziyao
More information about the busybox
mailing list