aboutsummaryrefslogtreecommitdiff
path: root/mv.c
diff options
context:
space:
mode:
Diffstat (limited to 'mv.c')
-rw-r--r--mv.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/mv.c b/mv.c
index 2be3961ca..d0f346196 100644
--- a/mv.c
+++ b/mv.c
@@ -35,13 +35,25 @@ static const char mv_usage[] = "mv SOURCE DEST\n"
35 35
36static const char *srcName; 36static const char *srcName;
37static const char *destName; 37static const char *destName;
38static const char *skipName;
39static int dirFlag = FALSE; 38static int dirFlag = FALSE;
40 39
40static int fileAction(const char *fileName, struct stat* statbuf)
41{
42 char newdestName[NAME_MAX];
43
44 fprintf(stderr, "srcName='%s' destName='%s'\n", srcName, destName);
45 strcpy(newdestName, destName);
46 strcat(newdestName, "/");
47 strcat(newdestName, strstr(fileName, fileName));
48 fprintf(stderr, "newdestName='%s'\n", newdestName);
49 return (copyFile(fileName, newdestName, TRUE, TRUE));
50}
51
41 52
42extern int mv_main(int argc, char **argv) 53extern int mv_main(int argc, char **argv)
43{ 54{
44 char newdestName[NAME_MAX]; 55 char newdestName[NAME_MAX];
56 char *skipName;
45 57
46 if (argc < 3) { 58 if (argc < 3) {
47 usage (mv_usage); 59 usage (mv_usage);
@@ -69,16 +81,26 @@ extern int mv_main(int argc, char **argv)
69 strcat(newdestName, strstr(srcName, skipName)); 81 strcat(newdestName, strstr(srcName, skipName));
70 else 82 else
71 strcat(newdestName, srcName); 83 strcat(newdestName, srcName);
72 fprintf(stderr, "srcName='%s'\n", srcName);
73 fprintf(stderr, "skipName='%s'\n", skipName);
74 fprintf(stderr, "newdestName='%s'\n", newdestName);
75 }
76 if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
77 exit( FALSE);
78 } 84 }
79 if (unlink (srcName) < 0) { 85 if (isDirectory(srcName)==TRUE && newdestName[strlen(newdestName)] != '/') {
80 perror (srcName); 86 strcat(newdestName, "/");
81 exit( FALSE); 87 createPath(newdestName, 0777);
88 fprintf(stderr, "srcName = '%s'\n", srcName);
89 fprintf(stderr, "newdestName = '%s'\n", newdestName);
90 if (recursiveAction(srcName, TRUE, TRUE, FALSE,
91 fileAction, fileAction) == FALSE)
92 {
93 exit( FALSE);
94 }
95 exit( TRUE);
96 } else {
97 if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
98 exit( FALSE);
99 }
100 if (unlink (srcName) < 0) {
101 perror (srcName);
102 exit( FALSE);
103 }
82 } 104 }
83 } 105 }
84 exit( TRUE); 106 exit( TRUE);