diff options
author | Erik Andersen <andersen@codepoet.org> | 1999-12-29 02:10:35 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 1999-12-29 02:10:35 +0000 |
commit | 2fe08c7afb3ddef42f304e78cb6edfa28e0741ef (patch) | |
tree | 2c44125f9324373494668c513c31be2a172a54d4 /coreutils/cp.c | |
parent | 00266d3df6ba8dcc6247f112372a0ce5a8ab2c32 (diff) | |
download | busybox-w32-2fe08c7afb3ddef42f304e78cb6edfa28e0741ef.tar.gz busybox-w32-2fe08c7afb3ddef42f304e78cb6edfa28e0741ef.tar.bz2 busybox-w32-2fe08c7afb3ddef42f304e78cb6edfa28e0741ef.zip |
Fixed cp so it works as God intended it to.
-Erik
Diffstat (limited to 'coreutils/cp.c')
-rw-r--r-- | coreutils/cp.c | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/coreutils/cp.c b/coreutils/cp.c index ce632016e..1e10f2868 100644 --- a/coreutils/cp.c +++ b/coreutils/cp.c | |||
@@ -42,26 +42,36 @@ static int followLinks = FALSE; | |||
42 | static int preserveFlag = FALSE; | 42 | static int preserveFlag = FALSE; |
43 | static const char *srcName; | 43 | static const char *srcName; |
44 | static const char *destName; | 44 | static const char *destName; |
45 | static const char *skipName; | 45 | static int destDirFlag = FALSE; |
46 | static int dirFlag = FALSE; | 46 | static int destExistsFlag = FALSE; |
47 | 47 | static int srcDirFlag = FALSE; | |
48 | 48 | ||
49 | static int fileAction(const char *fileName, struct stat* statbuf) | 49 | static int fileAction(const char *fileName, struct stat* statbuf) |
50 | { | 50 | { |
51 | char newdestName[NAME_MAX]; | 51 | char newdestName[NAME_MAX]; |
52 | |||
52 | strcpy(newdestName, destName); | 53 | strcpy(newdestName, destName); |
53 | if (dirFlag==TRUE) { | 54 | if ( srcDirFlag == TRUE ) { |
54 | strcat(newdestName, "/"); | 55 | if (recursiveFlag!=TRUE ) { |
55 | if ( skipName != NULL) | 56 | fprintf(stderr, "cp: %s: omitting directory\n", srcName); |
56 | strcat(newdestName, strstr(fileName, skipName)); | 57 | return( TRUE); |
57 | else | 58 | } |
58 | strcat(newdestName, srcName); | 59 | strcat(newdestName, strstr(fileName, srcName) + strlen(srcName)); |
60 | } | ||
61 | |||
62 | if (destDirFlag==TRUE && srcDirFlag == FALSE) { | ||
63 | if (newdestName[strlen(newdestName)-1] != '/' ) { | ||
64 | strcat(newdestName, "/"); | ||
65 | } | ||
66 | strcat(newdestName, srcName); | ||
59 | } | 67 | } |
68 | |||
60 | return (copyFile(fileName, newdestName, preserveFlag, followLinks)); | 69 | return (copyFile(fileName, newdestName, preserveFlag, followLinks)); |
61 | } | 70 | } |
62 | 71 | ||
63 | extern int cp_main(int argc, char **argv) | 72 | extern int cp_main(int argc, char **argv) |
64 | { | 73 | { |
74 | struct stat statBuf; | ||
65 | 75 | ||
66 | if (argc < 3) { | 76 | if (argc < 3) { |
67 | usage (cp_usage); | 77 | usage (cp_usage); |
@@ -96,18 +106,20 @@ extern int cp_main(int argc, char **argv) | |||
96 | 106 | ||
97 | 107 | ||
98 | destName = argv[argc - 1]; | 108 | destName = argv[argc - 1]; |
99 | dirFlag = isDirectory(destName); | 109 | if (stat(destName, &statBuf) >= 0) { |
110 | destExistsFlag = TRUE; | ||
111 | if (S_ISDIR(statBuf.st_mode)) | ||
112 | destDirFlag = TRUE; | ||
113 | } | ||
100 | 114 | ||
101 | if ((argc > 3) && dirFlag==FALSE) { | 115 | if ((argc > 3) && destDirFlag==FALSE) { |
102 | fprintf(stderr, "%s: not a directory\n", destName); | 116 | fprintf(stderr, "%s: not a directory\n", destName); |
103 | exit (FALSE); | 117 | exit (FALSE); |
104 | } | 118 | } |
105 | 119 | ||
106 | while (argc-- > 1) { | 120 | while (argc-- > 1) { |
107 | srcName = *(argv++); | 121 | srcName = *(argv++); |
108 | skipName = strrchr(srcName, '/'); | 122 | srcDirFlag = isDirectory(srcName); |
109 | if (skipName) | ||
110 | skipName++; | ||
111 | if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE, | 123 | if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE, |
112 | fileAction, fileAction) == FALSE) { | 124 | fileAction, fileAction) == FALSE) { |
113 | exit( FALSE); | 125 | exit( FALSE); |