Applied patch from Christophe Boyanique to add -i support to rm.
authorMark Whitley <markw@lineo.com>
Tue, 13 Mar 2001 00:40:19 +0000 (00:40 -0000)
committerMark Whitley <markw@lineo.com>
Tue, 13 Mar 2001 00:40:19 +0000 (00:40 -0000)
Config.h
Config.h.Hurd
applets/usage.h
busybox.h
coreutils/rm.c
docs/busybox.sgml
include/busybox.h
include/usage.h
rm.c
usage.h
utility.c

index 6492b893f1d86f6d65764fac66a6193e493bf0c3..779064da45144315efc2e4c20b18fb558c7c0854 100644 (file)
--- a/Config.h
+++ b/Config.h
 // (i.e. in case of an unreachable NFS system).
 #define BB_FEATURE_MOUNT_FORCE
 //
+// use -i (interactive) flag for rm
+//#define BB_FEATURE_RM_INTERACTIVE
+//
 // Enable support for creation of tar files.
 #define BB_FEATURE_TAR_CREATE
 //
index 9238761a20c6b49166969ac264bc3d802265cb3c..0320f8ab236f1cd7c86a56ac647b4a67e2aa277b 100644 (file)
 // (i.e. in case of an unreachable NFS system).
 #define BB_FEATURE_MOUNT_FORCE
 //
+// use -i (interactive) flag for rm
+//#define BB_FEATURE_RM_INTERACTIVE
+//
 // Enable support for creation of tar files.
 #define BB_FEATURE_TAR_CREATE
 //
index f241d3a043a662524bdc9c85c64143a401c8ee92..f316018c847f3ff4a42c685689dd21a3c829f851 100644 (file)
 #define reset_full_usage \
        "Resets the screen."
 
+#ifdef BB_FEATURE_RM_INTERACTIVE
+  #define USAGE_RM_INTERACTIVE(a) a
+#else
+  #define USAGE_RM_INTERACTIVE(a)
+#endif
 #define rm_trivial_usage \
        "[OPTION]... FILE..."
 #define rm_full_usage \
        "Remove (unlink) the FILE(s).  You may use '--' to\n" \
        "indicate that all following arguments are non-options.\n\n" \
        "Options:\n" \
+       USAGE_RM_INTERACTIVE("\t-i\t\talways prompt before removing each destinations\n") \
        "\t-f\t\tremove existing destinations, never prompt\n" \
        "\t-r or -R\tremove the contents of directories recursively"
 
index abf62410f9046f722294a8793c50f0455bbb850e..7ae64850190b96599ef7d6b591120647732ec50a 100644 (file)
--- a/busybox.h
+++ b/busybox.h
@@ -255,4 +255,8 @@ enum {
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
 #endif
 
+#if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM)
+int ask_confirmation(void);
+#endif
+
 #endif /* _BB_INTERNAL_H_ */
index a84163272e3b8ae9ae9035e85977fb3eba2031b2..6d92b5daabf15d1590125a239653dd8d4210380e 100644 (file)
 
 static int recursiveFlag = FALSE;
 static int forceFlag = FALSE;
+#ifdef BB_FEATURE_RM_INTERACTIVE
+       static int interactiveFlag = FALSE;
+#endif
 static const char *srcName;
 
 
 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
 {
+#ifdef BB_FEATURE_RM_INTERACTIVE
+       if (interactiveFlag == TRUE) {
+               printf("rm: remove `%s'? ", fileName);
+               if (ask_confirmation() == 0)
+                       return (TRUE);
+       }
+#endif
        if (unlink(fileName) < 0) {
                perror_msg("%s", fileName);
                return (FALSE);
@@ -52,6 +62,13 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
                perror_msg("%s", fileName);
                return (FALSE);
        } 
+#ifdef BB_FEATURE_RM_INTERACTIVE
+       if (interactiveFlag == TRUE) {
+               printf("rm: remove directory `%s'? ", fileName);
+               if (ask_confirmation() == 0)
+                       return (TRUE);
+       }
+#endif
        if (rmdir(fileName) < 0) {
                perror_msg("%s", fileName);
                return (FALSE);
@@ -79,6 +96,14 @@ extern int rm_main(int argc, char **argv)
                                                break;
                                        case 'f':
                                                forceFlag = TRUE;
+#ifdef BB_FEATURE_RM_INTERACTIVE
+                                               interactiveFlag = FALSE;
+#endif
+                                               break;
+                                       case 'i':
+#ifdef BB_FEATURE_RM_INTERACTIVE
+                                               interactiveFlag = TRUE;
+#endif
                                                break;
                                        case '-':
                                                stopIt = TRUE;
index 02d85e499fcb8d2fcd10af176aa341e563c10205..f794f896cc66880d7e209ca682f232f659b2296f 100644 (file)
 
                <para>
                <screen>
+                       -i              Always prompt before removing each destinations
                        -f              Remove existing destinations, never prompt
                        -r or -R        Remove the contents of directories recursively
                </screen>
index abf62410f9046f722294a8793c50f0455bbb850e..7ae64850190b96599ef7d6b591120647732ec50a 100644 (file)
@@ -255,4 +255,8 @@ enum {
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
 #endif
 
+#if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM)
+int ask_confirmation(void);
+#endif
+
 #endif /* _BB_INTERNAL_H_ */
index f241d3a043a662524bdc9c85c64143a401c8ee92..f316018c847f3ff4a42c685689dd21a3c829f851 100644 (file)
 #define reset_full_usage \
        "Resets the screen."
 
+#ifdef BB_FEATURE_RM_INTERACTIVE
+  #define USAGE_RM_INTERACTIVE(a) a
+#else
+  #define USAGE_RM_INTERACTIVE(a)
+#endif
 #define rm_trivial_usage \
        "[OPTION]... FILE..."
 #define rm_full_usage \
        "Remove (unlink) the FILE(s).  You may use '--' to\n" \
        "indicate that all following arguments are non-options.\n\n" \
        "Options:\n" \
+       USAGE_RM_INTERACTIVE("\t-i\t\talways prompt before removing each destinations\n") \
        "\t-f\t\tremove existing destinations, never prompt\n" \
        "\t-r or -R\tremove the contents of directories recursively"
 
diff --git a/rm.c b/rm.c
index a84163272e3b8ae9ae9035e85977fb3eba2031b2..6d92b5daabf15d1590125a239653dd8d4210380e 100644 (file)
--- a/rm.c
+++ b/rm.c
 
 static int recursiveFlag = FALSE;
 static int forceFlag = FALSE;
+#ifdef BB_FEATURE_RM_INTERACTIVE
+       static int interactiveFlag = FALSE;
+#endif
 static const char *srcName;
 
 
 static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
 {
+#ifdef BB_FEATURE_RM_INTERACTIVE
+       if (interactiveFlag == TRUE) {
+               printf("rm: remove `%s'? ", fileName);
+               if (ask_confirmation() == 0)
+                       return (TRUE);
+       }
+#endif
        if (unlink(fileName) < 0) {
                perror_msg("%s", fileName);
                return (FALSE);
@@ -52,6 +62,13 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
                perror_msg("%s", fileName);
                return (FALSE);
        } 
+#ifdef BB_FEATURE_RM_INTERACTIVE
+       if (interactiveFlag == TRUE) {
+               printf("rm: remove directory `%s'? ", fileName);
+               if (ask_confirmation() == 0)
+                       return (TRUE);
+       }
+#endif
        if (rmdir(fileName) < 0) {
                perror_msg("%s", fileName);
                return (FALSE);
@@ -79,6 +96,14 @@ extern int rm_main(int argc, char **argv)
                                                break;
                                        case 'f':
                                                forceFlag = TRUE;
+#ifdef BB_FEATURE_RM_INTERACTIVE
+                                               interactiveFlag = FALSE;
+#endif
+                                               break;
+                                       case 'i':
+#ifdef BB_FEATURE_RM_INTERACTIVE
+                                               interactiveFlag = TRUE;
+#endif
                                                break;
                                        case '-':
                                                stopIt = TRUE;
diff --git a/usage.h b/usage.h
index f241d3a043a662524bdc9c85c64143a401c8ee92..f316018c847f3ff4a42c685689dd21a3c829f851 100644 (file)
--- a/usage.h
+++ b/usage.h
 #define reset_full_usage \
        "Resets the screen."
 
+#ifdef BB_FEATURE_RM_INTERACTIVE
+  #define USAGE_RM_INTERACTIVE(a) a
+#else
+  #define USAGE_RM_INTERACTIVE(a)
+#endif
 #define rm_trivial_usage \
        "[OPTION]... FILE..."
 #define rm_full_usage \
        "Remove (unlink) the FILE(s).  You may use '--' to\n" \
        "indicate that all following arguments are non-options.\n\n" \
        "Options:\n" \
+       USAGE_RM_INTERACTIVE("\t-i\t\talways prompt before removing each destinations\n") \
        "\t-f\t\tremove existing destinations, never prompt\n" \
        "\t-r or -R\tremove the contents of directories recursively"
 
index c557130b9fd9e300bf3895257afd6061a6f5b3d6..8e85894d08640bc142d1fe4b517f35825bf2d045 100644 (file)
--- a/utility.c
+++ b/utility.c
@@ -1859,6 +1859,24 @@ void trim(char *s)
 }
 #endif
 
+#ifdef BB_FEATURE_RM_INTERACTIVE
+       #if defined (BB_CP_MV) || defined (BB_RM)
+int ask_confirmation()
+{
+       int c = '\0';
+       int ret = 0;
+
+       while (c != '\n') {
+               c = getchar();
+               if ( c != '\n' ) {
+                       ret = ((c=='y')||(c=='Y')) ? 1 : 0;
+               }
+       }
+       return ret;
+}
+       #endif
+#endif
+
 /* END CODE */
 /*
 Local Variables: