mirror of
https://github.com/sheumann/hush.git
synced 2024-11-19 08:31:11 +00:00
More fixes
This commit is contained in:
parent
9b58718889
commit
bed30e9700
@ -39,12 +39,12 @@
|
|||||||
//#define BB_PRINTF
|
//#define BB_PRINTF
|
||||||
#define BB_PWD
|
#define BB_PWD
|
||||||
#define BB_REBOOT
|
#define BB_REBOOT
|
||||||
//#define BB_RM
|
#define BB_RM
|
||||||
#define BB_RMDIR
|
#define BB_RMDIR
|
||||||
#define BB_SLEEP
|
#define BB_SLEEP
|
||||||
////#define BB_SWAPOFF
|
////#define BB_SWAPOFF
|
||||||
//#define BB_SWAPON
|
//#define BB_SWAPON
|
||||||
//#define BB_SYNC
|
#define BB_SYNC
|
||||||
#define BB_TAR
|
#define BB_TAR
|
||||||
#define BB_TOUCH
|
#define BB_TOUCH
|
||||||
#define BB_TRUE
|
#define BB_TRUE
|
||||||
|
@ -138,7 +138,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
|||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
while (argc-- > 1) {
|
while (argc-- > 1) {
|
||||||
if (recursiveAction( *(++argv), recursiveFlag, TRUE, fileAction, fileAction)==FALSE)
|
if (recursiveAction( *(++argv), recursiveFlag, TRUE, FALSE, fileAction, fileAction)==FALSE)
|
||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
exit(TRUE);
|
exit(TRUE);
|
||||||
|
@ -48,7 +48,7 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
|||||||
{
|
{
|
||||||
char newdestName[NAME_MAX];
|
char newdestName[NAME_MAX];
|
||||||
strcpy(newdestName, destName);
|
strcpy(newdestName, destName);
|
||||||
if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
|
if (dirFlag==TRUE) {
|
||||||
strcat(newdestName, "/");
|
strcat(newdestName, "/");
|
||||||
if ( skipName != NULL)
|
if ( skipName != NULL)
|
||||||
strcat(newdestName, strstr(fileName, skipName));
|
strcat(newdestName, strstr(fileName, skipName));
|
||||||
@ -104,10 +104,12 @@ extern int cp_main(int argc, char **argv)
|
|||||||
while (argc-- > 1) {
|
while (argc-- > 1) {
|
||||||
srcName = *(argv++);
|
srcName = *(argv++);
|
||||||
skipName = strrchr(srcName, '/');
|
skipName = strrchr(srcName, '/');
|
||||||
if (skipName) skipName++;
|
if (skipName)
|
||||||
if (recursiveAction(srcName, recursiveFlag, followLinks,
|
skipName++;
|
||||||
fileAction, fileAction) == FALSE)
|
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||||
|
fileAction, fileAction) == FALSE) {
|
||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exit( TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ static int dirAction(const char *fileName)
|
|||||||
exit(FALSE);
|
exit(FALSE);
|
||||||
}
|
}
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
|
recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction);
|
||||||
}
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
@ -21,63 +21,59 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <time.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
#include <errno.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
const char mv_usage[] = "source-file [source-file ...] destination-file\n"
|
|
||||||
"\n" "\tMove the source files to the destination.\n" "\n";
|
|
||||||
|
|
||||||
|
|
||||||
|
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||||
|
" or: mv SOURCE... DIRECTORY\n"
|
||||||
|
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||||
|
|
||||||
extern int mv_main (int argc, char **argv)
|
|
||||||
|
static const char *srcName;
|
||||||
|
static const char *destName;
|
||||||
|
static const char *skipName;
|
||||||
|
static int dirFlag = FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
extern int mv_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *srcName;
|
char newdestName[NAME_MAX];
|
||||||
const char *destName;
|
|
||||||
const char *lastArg;
|
|
||||||
int dirFlag;
|
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
|
fprintf(stderr, "Usage: %s", mv_usage);
|
||||||
exit (FALSE);
|
exit (FALSE);
|
||||||
}
|
}
|
||||||
lastArg = argv[argc - 1];
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
dirFlag = isDirectory (lastArg);
|
destName = argv[argc - 1];
|
||||||
|
dirFlag = isDirectory(destName);
|
||||||
|
|
||||||
if ((argc > 3) && !dirFlag) {
|
if ((argc > 3) && dirFlag==FALSE) {
|
||||||
fprintf (stderr, "%s: not a directory\n", lastArg);
|
fprintf(stderr, "%s: not a directory\n", destName);
|
||||||
exit (FALSE);
|
exit (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (argc-- > 2) {
|
while (argc-- > 1) {
|
||||||
srcName = *(++argv);
|
srcName = *(argv++);
|
||||||
|
skipName = strrchr(srcName, '/');
|
||||||
if (access (srcName, 0) < 0) {
|
if (skipName)
|
||||||
perror (srcName);
|
skipName++;
|
||||||
continue;
|
strcpy(newdestName, destName);
|
||||||
|
if (dirFlag==TRUE) {
|
||||||
|
strcat(newdestName, "/");
|
||||||
|
if ( skipName != NULL)
|
||||||
|
strcat(newdestName, strstr(srcName, skipName));
|
||||||
}
|
}
|
||||||
|
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
|
||||||
destName = lastArg;
|
exit( FALSE);
|
||||||
|
|
||||||
if (dirFlag==TRUE)
|
|
||||||
destName = buildName (destName, srcName);
|
|
||||||
|
|
||||||
if (rename (srcName, destName) >= 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (errno != EXDEV) {
|
|
||||||
perror (destName);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
if (unlink (srcName) < 0) {
|
||||||
if (!copyFile (srcName, destName, TRUE, FALSE))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (unlink (srcName) < 0)
|
|
||||||
perror (srcName);
|
perror (srcName);
|
||||||
|
exit( FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exit (TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
105
coreutils/rm.c
105
coreutils/rm.c
@ -1,30 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Mini rm implementation for busybox
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <errno.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <utime.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
const char rm_usage[] = "rm [-r] file [file ...]\n"
|
static const char* rm_usage = "Usage: rm [OPTION]... FILE...\n"
|
||||||
"\n"
|
"Remove (unlink) the FILE(s).\n\n"
|
||||||
"\tDelete files.\n"
|
"\t-f\tremove existing destinations, never prompt\n"
|
||||||
"\n"
|
"\t-r\tremove the contents of directories recursively\n";
|
||||||
"\t-r:\tRecursively remove files and directories.\n";
|
|
||||||
|
|
||||||
extern int
|
|
||||||
rm_main(struct FileInfo * i, int argc, char * * argv)
|
static int recursiveFlag = FALSE;
|
||||||
|
static int forceFlag = FALSE;
|
||||||
|
static const char *srcName;
|
||||||
|
|
||||||
|
|
||||||
|
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||||
{
|
{
|
||||||
i->processDirectoriesAfterTheirContents = 1;
|
if (unlink( fileName) < 0 ) {
|
||||||
return monadic_main(i, argc, argv);
|
perror( fileName);
|
||||||
|
return ( FALSE);
|
||||||
|
}
|
||||||
|
return ( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int
|
static int dirAction(const char *fileName, struct stat* statbuf)
|
||||||
rm_fn(const struct FileInfo * i)
|
|
||||||
{
|
{
|
||||||
if ( i->recursive
|
if (rmdir( fileName) < 0 ) {
|
||||||
&& !i->isSymbolicLink
|
perror( fileName);
|
||||||
&& (i->stat.st_mode & S_IFMT) == S_IFDIR )
|
return ( FALSE);
|
||||||
return rmdir_fn(i);
|
}
|
||||||
else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) {
|
return ( TRUE);
|
||||||
name_and_error(i->source);
|
}
|
||||||
return 1;
|
|
||||||
|
extern int rm_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
fprintf(stderr, "Usage: %s", rm_usage);
|
||||||
|
exit (FALSE);
|
||||||
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
/* Parse any options */
|
||||||
|
while (**argv == '-') {
|
||||||
|
while (*++(*argv))
|
||||||
|
switch (**argv) {
|
||||||
|
case 'r':
|
||||||
|
recursiveFlag = TRUE;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
forceFlag = TRUE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Usage: %s\n", rm_usage);
|
||||||
|
exit(FALSE);
|
||||||
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (argc-- > 0) {
|
||||||
|
srcName = *(argv++);
|
||||||
|
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
|
||||||
|
fileAction, dirAction) == FALSE) {
|
||||||
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
return 0;
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
const char sync_usage[] = "sync\n"
|
|
||||||
"\n"
|
|
||||||
"\tWrite all buffered filesystem blocks to disk.\n";
|
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
sync_main(struct FileInfo * i, int argc, char * * argv)
|
sync_main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
|
if ( **(argv+1) == '-' ) {
|
||||||
|
fprintf(stderr, "Usage: sync\nWrite all buffered filesystem blocks to disk.\n");
|
||||||
|
exit(FALSE);
|
||||||
|
}
|
||||||
return sync();
|
return sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
cp.c
10
cp.c
@ -48,7 +48,7 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
|||||||
{
|
{
|
||||||
char newdestName[NAME_MAX];
|
char newdestName[NAME_MAX];
|
||||||
strcpy(newdestName, destName);
|
strcpy(newdestName, destName);
|
||||||
if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
|
if (dirFlag==TRUE) {
|
||||||
strcat(newdestName, "/");
|
strcat(newdestName, "/");
|
||||||
if ( skipName != NULL)
|
if ( skipName != NULL)
|
||||||
strcat(newdestName, strstr(fileName, skipName));
|
strcat(newdestName, strstr(fileName, skipName));
|
||||||
@ -104,10 +104,12 @@ extern int cp_main(int argc, char **argv)
|
|||||||
while (argc-- > 1) {
|
while (argc-- > 1) {
|
||||||
srcName = *(argv++);
|
srcName = *(argv++);
|
||||||
skipName = strrchr(srcName, '/');
|
skipName = strrchr(srcName, '/');
|
||||||
if (skipName) skipName++;
|
if (skipName)
|
||||||
if (recursiveAction(srcName, recursiveFlag, followLinks,
|
skipName++;
|
||||||
fileAction, fileAction) == FALSE)
|
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||||
|
fileAction, fileAction) == FALSE) {
|
||||||
exit( FALSE);
|
exit( FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exit( TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
33
find.c
33
find.c
@ -62,7 +62,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
|
|||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
char dirName[NAME_MAX];
|
char dirName[NAME_MAX];
|
||||||
sprintf(dirName, "%s/%s", fileName, entry->d_name);
|
sprintf(dirName, "%s/%s", fileName, entry->d_name);
|
||||||
recursiveAction( dirName, TRUE, dereferenceFlag, fileAction, dirAction);
|
recursiveAction( dirName, TRUE, dereferenceFlag, FALSE, fileAction, dirAction);
|
||||||
}
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
@ -123,34 +123,3 @@ int find_main(int argc, char **argv)
|
|||||||
dirAction( directory, NULL);
|
dirAction( directory, NULL);
|
||||||
exit(TRUE);
|
exit(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef foobar
|
|
||||||
|
|
||||||
#include "internal.h"
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
const char find_usage[] = "find dir [pattern]\n"
|
|
||||||
"\n"
|
|
||||||
"\tFind files.\n";
|
|
||||||
|
|
||||||
extern int
|
|
||||||
find_main(struct FileInfo * i, int argc, char * * argv)
|
|
||||||
{
|
|
||||||
i->recursive=1;
|
|
||||||
i->processDirectoriesAfterTheirContents=1;
|
|
||||||
return monadic_main(i, argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern int
|
|
||||||
find_fn(const struct FileInfo * i)
|
|
||||||
{
|
|
||||||
printf("%s\n",i->source);
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -62,7 +62,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
|
|||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
char dirName[NAME_MAX];
|
char dirName[NAME_MAX];
|
||||||
sprintf(dirName, "%s/%s", fileName, entry->d_name);
|
sprintf(dirName, "%s/%s", fileName, entry->d_name);
|
||||||
recursiveAction( dirName, TRUE, dereferenceFlag, fileAction, dirAction);
|
recursiveAction( dirName, TRUE, dereferenceFlag, FALSE, fileAction, dirAction);
|
||||||
}
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
@ -123,34 +123,3 @@ int find_main(int argc, char **argv)
|
|||||||
dirAction( directory, NULL);
|
dirAction( directory, NULL);
|
||||||
exit(TRUE);
|
exit(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef foobar
|
|
||||||
|
|
||||||
#include "internal.h"
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
const char find_usage[] = "find dir [pattern]\n"
|
|
||||||
"\n"
|
|
||||||
"\tFind files.\n";
|
|
||||||
|
|
||||||
extern int
|
|
||||||
find_main(struct FileInfo * i, int argc, char * * argv)
|
|
||||||
{
|
|
||||||
i->recursive=1;
|
|
||||||
i->processDirectoriesAfterTheirContents=1;
|
|
||||||
return monadic_main(i, argc, argv);
|
|
||||||
}
|
|
||||||
|
|
||||||
extern int
|
|
||||||
find_fn(const struct FileInfo * i)
|
|
||||||
{
|
|
||||||
printf("%s\n",i->source);
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -121,7 +121,7 @@ char *chunkstrdup(const char *str);
|
|||||||
void freeChunks(void);
|
void freeChunks(void);
|
||||||
int fullWrite(int fd, const char *buf, int len);
|
int fullWrite(int fd, const char *buf, int len);
|
||||||
int fullRead(int fd, char *buf, int len);
|
int fullRead(int fd, char *buf, int len);
|
||||||
int recursiveAction(const char *fileName, int recurse, int followLinks,
|
int recursiveAction(const char *fileName, int recurse, int followLinks, int delayDirAction,
|
||||||
int (*fileAction) (const char *fileName, struct stat* statbuf),
|
int (*fileAction) (const char *fileName, struct stat* statbuf),
|
||||||
int (*dirAction) (const char *fileName, struct stat* statbuf));
|
int (*dirAction) (const char *fileName, struct stat* statbuf));
|
||||||
int match(const char* text, const char * pattern);
|
int match(const char* text, const char * pattern);
|
||||||
|
2
ls.c
2
ls.c
@ -68,7 +68,7 @@ static int dirAction(const char *fileName)
|
|||||||
exit(FALSE);
|
exit(FALSE);
|
||||||
}
|
}
|
||||||
while ((entry = readdir(dir)) != NULL) {
|
while ((entry = readdir(dir)) != NULL) {
|
||||||
recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
|
recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction);
|
||||||
}
|
}
|
||||||
return( TRUE);
|
return( TRUE);
|
||||||
}
|
}
|
||||||
|
78
mv.c
78
mv.c
@ -21,63 +21,59 @@
|
|||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <time.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
#include <errno.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
const char mv_usage[] = "source-file [source-file ...] destination-file\n"
|
|
||||||
"\n" "\tMove the source files to the destination.\n" "\n";
|
|
||||||
|
|
||||||
|
|
||||||
|
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||||
|
" or: mv SOURCE... DIRECTORY\n"
|
||||||
|
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||||
|
|
||||||
extern int mv_main (int argc, char **argv)
|
|
||||||
|
static const char *srcName;
|
||||||
|
static const char *destName;
|
||||||
|
static const char *skipName;
|
||||||
|
static int dirFlag = FALSE;
|
||||||
|
|
||||||
|
|
||||||
|
extern int mv_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *srcName;
|
char newdestName[NAME_MAX];
|
||||||
const char *destName;
|
|
||||||
const char *lastArg;
|
|
||||||
int dirFlag;
|
|
||||||
|
|
||||||
if (argc < 3) {
|
if (argc < 3) {
|
||||||
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
|
fprintf(stderr, "Usage: %s", mv_usage);
|
||||||
exit (FALSE);
|
exit (FALSE);
|
||||||
}
|
}
|
||||||
lastArg = argv[argc - 1];
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
dirFlag = isDirectory (lastArg);
|
destName = argv[argc - 1];
|
||||||
|
dirFlag = isDirectory(destName);
|
||||||
|
|
||||||
if ((argc > 3) && !dirFlag) {
|
if ((argc > 3) && dirFlag==FALSE) {
|
||||||
fprintf (stderr, "%s: not a directory\n", lastArg);
|
fprintf(stderr, "%s: not a directory\n", destName);
|
||||||
exit (FALSE);
|
exit (FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (argc-- > 2) {
|
while (argc-- > 1) {
|
||||||
srcName = *(++argv);
|
srcName = *(argv++);
|
||||||
|
skipName = strrchr(srcName, '/');
|
||||||
if (access (srcName, 0) < 0) {
|
if (skipName)
|
||||||
perror (srcName);
|
skipName++;
|
||||||
continue;
|
strcpy(newdestName, destName);
|
||||||
|
if (dirFlag==TRUE) {
|
||||||
|
strcat(newdestName, "/");
|
||||||
|
if ( skipName != NULL)
|
||||||
|
strcat(newdestName, strstr(srcName, skipName));
|
||||||
}
|
}
|
||||||
|
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
|
||||||
destName = lastArg;
|
exit( FALSE);
|
||||||
|
|
||||||
if (dirFlag==TRUE)
|
|
||||||
destName = buildName (destName, srcName);
|
|
||||||
|
|
||||||
if (rename (srcName, destName) >= 0)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (errno != EXDEV) {
|
|
||||||
perror (destName);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
if (unlink (srcName) < 0) {
|
||||||
if (!copyFile (srcName, destName, TRUE, FALSE))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (unlink (srcName) < 0)
|
|
||||||
perror (srcName);
|
perror (srcName);
|
||||||
|
exit( FALSE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exit (TRUE);
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
105
rm.c
105
rm.c
@ -1,30 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Mini rm implementation for busybox
|
||||||
|
*
|
||||||
|
* Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include <errno.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <utime.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
const char rm_usage[] = "rm [-r] file [file ...]\n"
|
static const char* rm_usage = "Usage: rm [OPTION]... FILE...\n"
|
||||||
"\n"
|
"Remove (unlink) the FILE(s).\n\n"
|
||||||
"\tDelete files.\n"
|
"\t-f\tremove existing destinations, never prompt\n"
|
||||||
"\n"
|
"\t-r\tremove the contents of directories recursively\n";
|
||||||
"\t-r:\tRecursively remove files and directories.\n";
|
|
||||||
|
|
||||||
extern int
|
|
||||||
rm_main(struct FileInfo * i, int argc, char * * argv)
|
static int recursiveFlag = FALSE;
|
||||||
|
static int forceFlag = FALSE;
|
||||||
|
static const char *srcName;
|
||||||
|
|
||||||
|
|
||||||
|
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||||
{
|
{
|
||||||
i->processDirectoriesAfterTheirContents = 1;
|
if (unlink( fileName) < 0 ) {
|
||||||
return monadic_main(i, argc, argv);
|
perror( fileName);
|
||||||
|
return ( FALSE);
|
||||||
|
}
|
||||||
|
return ( TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int
|
static int dirAction(const char *fileName, struct stat* statbuf)
|
||||||
rm_fn(const struct FileInfo * i)
|
|
||||||
{
|
{
|
||||||
if ( i->recursive
|
if (rmdir( fileName) < 0 ) {
|
||||||
&& !i->isSymbolicLink
|
perror( fileName);
|
||||||
&& (i->stat.st_mode & S_IFMT) == S_IFDIR )
|
return ( FALSE);
|
||||||
return rmdir_fn(i);
|
}
|
||||||
else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) {
|
return ( TRUE);
|
||||||
name_and_error(i->source);
|
}
|
||||||
return 1;
|
|
||||||
|
extern int rm_main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
fprintf(stderr, "Usage: %s", rm_usage);
|
||||||
|
exit (FALSE);
|
||||||
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
|
/* Parse any options */
|
||||||
|
while (**argv == '-') {
|
||||||
|
while (*++(*argv))
|
||||||
|
switch (**argv) {
|
||||||
|
case 'r':
|
||||||
|
recursiveFlag = TRUE;
|
||||||
|
break;
|
||||||
|
case 'f':
|
||||||
|
forceFlag = TRUE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "Usage: %s\n", rm_usage);
|
||||||
|
exit(FALSE);
|
||||||
|
}
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (argc-- > 0) {
|
||||||
|
srcName = *(argv++);
|
||||||
|
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
|
||||||
|
fileAction, dirAction) == FALSE) {
|
||||||
|
exit( FALSE);
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
return 0;
|
exit( TRUE);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ swapoff_fn(const struct FileInfo * i)
|
|||||||
{
|
{
|
||||||
struct mntent entries[100];
|
struct mntent entries[100];
|
||||||
int count = 0;
|
int count = 0;
|
||||||
FILE * swapsTable = setmntent("/etc/swaps", "r");
|
FILE * swapsTable = setmntent("/proc/swaps", "r");
|
||||||
struct mntent * m;
|
struct mntent * m;
|
||||||
|
|
||||||
if (!(swapoff(i->source))) {
|
if (!(swapoff(i->source))) {
|
||||||
|
11
sync.c
11
sync.c
@ -1,11 +1,12 @@
|
|||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
const char sync_usage[] = "sync\n"
|
|
||||||
"\n"
|
|
||||||
"\tWrite all buffered filesystem blocks to disk.\n";
|
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
sync_main(struct FileInfo * i, int argc, char * * argv)
|
sync_main(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
|
if ( **(argv+1) == '-' ) {
|
||||||
|
fprintf(stderr, "Usage: sync\nWrite all buffered filesystem blocks to disk.\n");
|
||||||
|
exit(FALSE);
|
||||||
|
}
|
||||||
return sync();
|
return sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
7
umount.c
7
umount.c
@ -26,8 +26,11 @@
|
|||||||
#include <fstab.h>
|
#include <fstab.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
const char umount_usage[] = "\tumount {filesystem|directory}\n"
|
const char umount_usage[] =
|
||||||
"or to unmount all mounted file systems:\n\tumount -a\n";
|
"Usage: umount filesystem\n"
|
||||||
|
" or: umount directory\n"
|
||||||
|
" or: umount -a"
|
||||||
|
"to unmount all mounted file systems.\n";
|
||||||
|
|
||||||
static int
|
static int
|
||||||
umount_all()
|
umount_all()
|
||||||
|
@ -26,8 +26,11 @@
|
|||||||
#include <fstab.h>
|
#include <fstab.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
const char umount_usage[] = "\tumount {filesystem|directory}\n"
|
const char umount_usage[] =
|
||||||
"or to unmount all mounted file systems:\n\tumount -a\n";
|
"Usage: umount filesystem\n"
|
||||||
|
" or: umount directory\n"
|
||||||
|
" or: umount -a"
|
||||||
|
"to unmount all mounted file systems.\n";
|
||||||
|
|
||||||
static int
|
static int
|
||||||
umount_all()
|
umount_all()
|
||||||
|
51
utility.c
51
utility.c
@ -188,36 +188,8 @@ copyFile( const char *srcName, const char *destName,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef BB_MV
|
|
||||||
/*
|
|
||||||
* Build a path name from the specified directory name and file name.
|
|
||||||
* If the directory name is NULL, then the original fileName is returned.
|
|
||||||
* The built path is in a static area, and is overwritten for each call.
|
|
||||||
*/
|
|
||||||
char *buildName(const char *dirName, const char *fileName)
|
|
||||||
{
|
|
||||||
const char *cp;
|
|
||||||
static char buf[PATH_LEN];
|
|
||||||
|
|
||||||
if ((dirName == NULL) || (*dirName == '\0')) {
|
|
||||||
strcpy(buf, fileName);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
cp = strrchr(fileName, '/');
|
|
||||||
|
|
||||||
if (cp)
|
|
||||||
fileName = cp + 1;
|
|
||||||
|
|
||||||
strcpy(buf, dirName);
|
|
||||||
strcat(buf, "/");
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef BB_TAR
|
||||||
/*
|
/*
|
||||||
* Return the standard ls-like mode string from a file mode.
|
* Return the standard ls-like mode string from a file mode.
|
||||||
* This is static and so is overwritten on each call.
|
* This is static and so is overwritten on each call.
|
||||||
@ -239,15 +211,10 @@ const char *modeString(int mode)
|
|||||||
buf[0] = 'b';
|
buf[0] = 'b';
|
||||||
if (S_ISFIFO(mode))
|
if (S_ISFIFO(mode))
|
||||||
buf[0] = 'p';
|
buf[0] = 'p';
|
||||||
#ifdef S_ISLNK
|
|
||||||
if (S_ISLNK(mode))
|
if (S_ISLNK(mode))
|
||||||
buf[0] = 'l';
|
buf[0] = 'l';
|
||||||
#endif
|
|
||||||
#ifdef S_ISSOCK
|
|
||||||
if (S_ISSOCK(mode))
|
if (S_ISSOCK(mode))
|
||||||
buf[0] = 's';
|
buf[0] = 's';
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now fill in the normal file permissions.
|
* Now fill in the normal file permissions.
|
||||||
*/
|
*/
|
||||||
@ -284,7 +251,6 @@ const char *modeString(int mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef BB_TAR
|
|
||||||
/*
|
/*
|
||||||
* Get the time string to be used for a file.
|
* Get the time string to be used for a file.
|
||||||
* This is down to the minute for new files, but only the date for old files.
|
* This is down to the minute for new files, but only the date for old files.
|
||||||
@ -467,7 +433,7 @@ int fullRead(int fd, char *buf, int len)
|
|||||||
* by the fileAction and dirAction function pointers).
|
* by the fileAction and dirAction function pointers).
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
recursiveAction(const char *fileName, int recurse, int followLinks,
|
recursiveAction(const char *fileName, int recurse, int followLinks, int delayDirAction,
|
||||||
int (*fileAction) (const char *fileName, struct stat* statbuf),
|
int (*fileAction) (const char *fileName, struct stat* statbuf),
|
||||||
int (*dirAction) (const char *fileName, struct stat* statbuf))
|
int (*dirAction) (const char *fileName, struct stat* statbuf))
|
||||||
{
|
{
|
||||||
@ -501,7 +467,7 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
|
|||||||
perror(fileName);
|
perror(fileName);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if (dirAction != NULL) {
|
if (dirAction != NULL && delayDirAction == FALSE) {
|
||||||
status = dirAction(fileName, &statbuf);
|
status = dirAction(fileName, &statbuf);
|
||||||
if (status == FALSE) {
|
if (status == FALSE) {
|
||||||
perror(fileName);
|
perror(fileName);
|
||||||
@ -516,8 +482,8 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
|
|||||||
}
|
}
|
||||||
sprintf(nextFile, "%s/%s", fileName, next->d_name);
|
sprintf(nextFile, "%s/%s", fileName, next->d_name);
|
||||||
status =
|
status =
|
||||||
recursiveAction(nextFile, TRUE, followLinks, fileAction,
|
recursiveAction(nextFile, TRUE, followLinks, delayDirAction,
|
||||||
dirAction);
|
fileAction, dirAction);
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
@ -528,6 +494,13 @@ recursiveAction(const char *fileName, int recurse, int followLinks,
|
|||||||
perror(fileName);
|
perror(fileName);
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
|
if (dirAction != NULL && delayDirAction == TRUE) {
|
||||||
|
status = dirAction(fileName, &statbuf);
|
||||||
|
if (status == FALSE) {
|
||||||
|
perror(fileName);
|
||||||
|
return (FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fileAction == NULL)
|
if (fileAction == NULL)
|
||||||
return (TRUE);
|
return (TRUE);
|
||||||
|
Loading…
Reference in New Issue
Block a user