More fixes

This commit is contained in:
Eric Andersen
1999-10-18 19:02:32 +00:00
parent 9b58718889
commit bed30e9700
19 changed files with 297 additions and 256 deletions

View File

@@ -48,7 +48,7 @@ static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
if (dirFlag==TRUE && newdestName[strlen(newdestName)-1]!= '/' ) {
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
@@ -104,10 +104,12 @@ extern int cp_main(int argc, char **argv)
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName) skipName++;
if (recursiveAction(srcName, recursiveFlag, followLinks,
fileAction, fileAction) == FALSE)
if (skipName)
skipName++;
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
}
exit( TRUE);
}

View File

@@ -68,7 +68,7 @@ static int dirAction(const char *fileName)
exit(FALSE);
}
while ((entry = readdir(dir)) != NULL) {
recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, fileAction, dirAction);
recursiveAction( entry->d_name, recursiveFlag, dereferenceFlag, FALSE, fileAction, dirAction);
}
return( TRUE);
}

View File

@@ -21,63 +21,59 @@
#include "internal.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <utime.h>
#include <errno.h>
const char mv_usage[] = "source-file [source-file ...] destination-file\n"
"\n" "\tMove the source files to the destination.\n" "\n";
#include <dirent.h>
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;
const char *destName;
const char *lastArg;
int dirFlag;
char newdestName[NAME_MAX];
if (argc < 3) {
fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
fprintf(stderr, "Usage: %s", mv_usage);
exit (FALSE);
}
lastArg = argv[argc - 1];
argc--;
argv++;
dirFlag = isDirectory (lastArg);
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
if ((argc > 3) && !dirFlag) {
fprintf (stderr, "%s: not a directory\n", lastArg);
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 2) {
srcName = *(++argv);
if (access (srcName, 0) < 0) {
perror (srcName);
continue;
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName)
skipName++;
strcpy(newdestName, destName);
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(srcName, skipName));
}
destName = lastArg;
if (dirFlag==TRUE)
destName = buildName (destName, srcName);
if (rename (srcName, destName) >= 0)
continue;
if (errno != EXDEV) {
perror (destName);
continue;
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
exit( FALSE);
}
if (!copyFile (srcName, destName, TRUE, FALSE))
continue;
if (unlink (srcName) < 0)
if (unlink (srcName) < 0) {
perror (srcName);
exit( FALSE);
}
}
exit (TRUE);
exit( TRUE);
}

View File

@@ -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 <errno.h>
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
const char rm_usage[] = "rm [-r] file [file ...]\n"
"\n"
"\tDelete files.\n"
"\n"
"\t-r:\tRecursively remove files and directories.\n";
static const char* rm_usage = "Usage: rm [OPTION]... FILE...\n"
"Remove (unlink) the FILE(s).\n\n"
"\t-f\tremove existing destinations, never prompt\n"
"\t-r\tremove the contents of directories recursively\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;
return monadic_main(i, argc, argv);
if (unlink( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
}
extern int
rm_fn(const struct FileInfo * i)
static int dirAction(const char *fileName, struct stat* statbuf)
{
if ( i->recursive
&& !i->isSymbolicLink
&& (i->stat.st_mode & S_IFMT) == S_IFDIR )
return rmdir_fn(i);
else if ( unlink(i->source) != 0 && errno != ENOENT && !i->force ) {
name_and_error(i->source);
return 1;
if (rmdir( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
}
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);
}

View File

@@ -1,11 +1,12 @@
#include "internal.h"
const char sync_usage[] = "sync\n"
"\n"
"\tWrite all buffered filesystem blocks to disk.\n";
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();
}