mirror of https://github.com/mirror/busybox.git
Applied patch from Christophe Boyanique to add -i support to rm.
parent
53737c5421
commit
e0bf91d7c6
3
Config.h
3
Config.h
|
@ -224,6 +224,9 @@
|
||||||
// (i.e. in case of an unreachable NFS system).
|
// (i.e. in case of an unreachable NFS system).
|
||||||
#define BB_FEATURE_MOUNT_FORCE
|
#define BB_FEATURE_MOUNT_FORCE
|
||||||
//
|
//
|
||||||
|
// use -i (interactive) flag for rm
|
||||||
|
//#define BB_FEATURE_RM_INTERACTIVE
|
||||||
|
//
|
||||||
// Enable support for creation of tar files.
|
// Enable support for creation of tar files.
|
||||||
#define BB_FEATURE_TAR_CREATE
|
#define BB_FEATURE_TAR_CREATE
|
||||||
//
|
//
|
||||||
|
|
|
@ -212,6 +212,9 @@
|
||||||
// (i.e. in case of an unreachable NFS system).
|
// (i.e. in case of an unreachable NFS system).
|
||||||
#define BB_FEATURE_MOUNT_FORCE
|
#define BB_FEATURE_MOUNT_FORCE
|
||||||
//
|
//
|
||||||
|
// use -i (interactive) flag for rm
|
||||||
|
//#define BB_FEATURE_RM_INTERACTIVE
|
||||||
|
//
|
||||||
// Enable support for creation of tar files.
|
// Enable support for creation of tar files.
|
||||||
#define BB_FEATURE_TAR_CREATE
|
#define BB_FEATURE_TAR_CREATE
|
||||||
//
|
//
|
||||||
|
|
|
@ -821,12 +821,18 @@
|
||||||
#define reset_full_usage \
|
#define reset_full_usage \
|
||||||
"Resets the screen."
|
"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 \
|
#define rm_trivial_usage \
|
||||||
"[OPTION]... FILE..."
|
"[OPTION]... FILE..."
|
||||||
#define rm_full_usage \
|
#define rm_full_usage \
|
||||||
"Remove (unlink) the FILE(s). You may use '--' to\n" \
|
"Remove (unlink) the FILE(s). You may use '--' to\n" \
|
||||||
"indicate that all following arguments are non-options.\n\n" \
|
"indicate that all following arguments are non-options.\n\n" \
|
||||||
"Options:\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-f\t\tremove existing destinations, never prompt\n" \
|
||||||
"\t-r or -R\tremove the contents of directories recursively"
|
"\t-r or -R\tremove the contents of directories recursively"
|
||||||
|
|
||||||
|
|
|
@ -255,4 +255,8 @@ enum {
|
||||||
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
|
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM)
|
||||||
|
int ask_confirmation(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _BB_INTERNAL_H_ */
|
#endif /* _BB_INTERNAL_H_ */
|
||||||
|
|
|
@ -33,11 +33,21 @@
|
||||||
|
|
||||||
static int recursiveFlag = FALSE;
|
static int recursiveFlag = FALSE;
|
||||||
static int forceFlag = FALSE;
|
static int forceFlag = FALSE;
|
||||||
|
#ifdef BB_FEATURE_RM_INTERACTIVE
|
||||||
|
static int interactiveFlag = FALSE;
|
||||||
|
#endif
|
||||||
static const char *srcName;
|
static const char *srcName;
|
||||||
|
|
||||||
|
|
||||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
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) {
|
if (unlink(fileName) < 0) {
|
||||||
perror_msg("%s", fileName);
|
perror_msg("%s", fileName);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
@ -52,6 +62,13 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||||
perror_msg("%s", fileName);
|
perror_msg("%s", fileName);
|
||||||
return (FALSE);
|
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) {
|
if (rmdir(fileName) < 0) {
|
||||||
perror_msg("%s", fileName);
|
perror_msg("%s", fileName);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
@ -79,6 +96,14 @@ extern int rm_main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
forceFlag = TRUE;
|
forceFlag = TRUE;
|
||||||
|
#ifdef BB_FEATURE_RM_INTERACTIVE
|
||||||
|
interactiveFlag = FALSE;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
#ifdef BB_FEATURE_RM_INTERACTIVE
|
||||||
|
interactiveFlag = TRUE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
stopIt = TRUE;
|
stopIt = TRUE;
|
||||||
|
|
|
@ -2728,6 +2728,7 @@
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<screen>
|
<screen>
|
||||||
|
-i Always prompt before removing each destinations
|
||||||
-f Remove existing destinations, never prompt
|
-f Remove existing destinations, never prompt
|
||||||
-r or -R Remove the contents of directories recursively
|
-r or -R Remove the contents of directories recursively
|
||||||
</screen>
|
</screen>
|
||||||
|
|
|
@ -255,4 +255,8 @@ enum {
|
||||||
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
|
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(BB_FEATURE_RM_INTERACTIVE) && defined(BB_RM)
|
||||||
|
int ask_confirmation(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _BB_INTERNAL_H_ */
|
#endif /* _BB_INTERNAL_H_ */
|
||||||
|
|
|
@ -821,12 +821,18 @@
|
||||||
#define reset_full_usage \
|
#define reset_full_usage \
|
||||||
"Resets the screen."
|
"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 \
|
#define rm_trivial_usage \
|
||||||
"[OPTION]... FILE..."
|
"[OPTION]... FILE..."
|
||||||
#define rm_full_usage \
|
#define rm_full_usage \
|
||||||
"Remove (unlink) the FILE(s). You may use '--' to\n" \
|
"Remove (unlink) the FILE(s). You may use '--' to\n" \
|
||||||
"indicate that all following arguments are non-options.\n\n" \
|
"indicate that all following arguments are non-options.\n\n" \
|
||||||
"Options:\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-f\t\tremove existing destinations, never prompt\n" \
|
||||||
"\t-r or -R\tremove the contents of directories recursively"
|
"\t-r or -R\tremove the contents of directories recursively"
|
||||||
|
|
||||||
|
|
25
rm.c
25
rm.c
|
@ -33,11 +33,21 @@
|
||||||
|
|
||||||
static int recursiveFlag = FALSE;
|
static int recursiveFlag = FALSE;
|
||||||
static int forceFlag = FALSE;
|
static int forceFlag = FALSE;
|
||||||
|
#ifdef BB_FEATURE_RM_INTERACTIVE
|
||||||
|
static int interactiveFlag = FALSE;
|
||||||
|
#endif
|
||||||
static const char *srcName;
|
static const char *srcName;
|
||||||
|
|
||||||
|
|
||||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
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) {
|
if (unlink(fileName) < 0) {
|
||||||
perror_msg("%s", fileName);
|
perror_msg("%s", fileName);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
@ -52,6 +62,13 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||||
perror_msg("%s", fileName);
|
perror_msg("%s", fileName);
|
||||||
return (FALSE);
|
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) {
|
if (rmdir(fileName) < 0) {
|
||||||
perror_msg("%s", fileName);
|
perror_msg("%s", fileName);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
@ -79,6 +96,14 @@ extern int rm_main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
forceFlag = TRUE;
|
forceFlag = TRUE;
|
||||||
|
#ifdef BB_FEATURE_RM_INTERACTIVE
|
||||||
|
interactiveFlag = FALSE;
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case 'i':
|
||||||
|
#ifdef BB_FEATURE_RM_INTERACTIVE
|
||||||
|
interactiveFlag = TRUE;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
stopIt = TRUE;
|
stopIt = TRUE;
|
||||||
|
|
6
usage.h
6
usage.h
|
@ -821,12 +821,18 @@
|
||||||
#define reset_full_usage \
|
#define reset_full_usage \
|
||||||
"Resets the screen."
|
"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 \
|
#define rm_trivial_usage \
|
||||||
"[OPTION]... FILE..."
|
"[OPTION]... FILE..."
|
||||||
#define rm_full_usage \
|
#define rm_full_usage \
|
||||||
"Remove (unlink) the FILE(s). You may use '--' to\n" \
|
"Remove (unlink) the FILE(s). You may use '--' to\n" \
|
||||||
"indicate that all following arguments are non-options.\n\n" \
|
"indicate that all following arguments are non-options.\n\n" \
|
||||||
"Options:\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-f\t\tremove existing destinations, never prompt\n" \
|
||||||
"\t-r or -R\tremove the contents of directories recursively"
|
"\t-r or -R\tremove the contents of directories recursively"
|
||||||
|
|
||||||
|
|
18
utility.c
18
utility.c
|
@ -1859,6 +1859,24 @@ void trim(char *s)
|
||||||
}
|
}
|
||||||
#endif
|
#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 */
|
/* END CODE */
|
||||||
/*
|
/*
|
||||||
Local Variables:
|
Local Variables:
|
||||||
|
|
Loading…
Reference in New Issue