summaryrefslogtreecommitdiff
path: root/mv.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-07 08:30:23 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-07 08:30:23 +0000
commit596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe (patch)
tree4d48d109e66c5197bb27c8215062aab28d385509 /mv.c
parent5c3199e0a519695c367b773e179b5458670f452b (diff)
downloadbusybox-w32-596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe.tar.gz
busybox-w32-596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe.tar.bz2
busybox-w32-596e5469d00fa4a74d8a3b1ebfaae20ce8dc3afe.zip
more stuff
Diffstat (limited to 'mv.c')
-rw-r--r--mv.c104
1 files changed, 75 insertions, 29 deletions
diff --git a/mv.c b/mv.c
index 22c4a1207..610040d92 100644
--- a/mv.c
+++ b/mv.c
@@ -1,38 +1,84 @@
1/*
2 * Mini mv implementation for busybox
3 *
4 * Copyright (C) 1998 by Erik Andersen <andersee@debian.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
1#include "internal.h" 22#include "internal.h"
2#include <stdio.h> 23#include <stdio.h>
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <fcntl.h>
27#include <utime.h>
3#include <errno.h> 28#include <errno.h>
4 29
5const char mv_usage[] = "mv source-file destination-file\n" 30const char mv_usage[] = "source-file [source-file ...] destination-file\n"
6"\t\tmv source-file [source-file ...] destination-directory\n" 31 "\n" "\tMove the source files to the destination.\n" "\n";
7"\n" 32
8"\tMove the source files to the destination.\n"
9"\n";
10 33
11extern int 34
12mv_fn(const struct FileInfo * i) 35extern int mv_main (int argc, char **argv)
13{ 36{
14 struct stat destination_stat; 37 const char *srcName;
15 char d[1024]; 38 const char *destName;
16 struct FileInfo n; 39 const char *lastArg;
17 40 BOOL dirFlag;
18 if ( stat(i->destination, &destination_stat) == 0 ) { 41
19 if ( i->stat.st_ino == destination_stat.st_ino 42 if (argc < 3) {
20 && i->stat.st_dev == destination_stat.st_dev ) 43 fprintf (stderr, "Usage: %s %s", *argv, mv_usage);
21 return 0; /* Move file to itself. */ 44 return (FALSE);
22 } 45 }
23 if ( (destination_stat.st_mode & S_IFMT) == S_IFDIR ) { 46 lastArg = argv[argc - 1];
24 n = *i; 47
25 n.destination = join_paths(d, i->destination, basename(i->source)); 48 dirFlag = isDirectory (lastArg);
26 i = &n; 49
50 if ((argc > 3) && !dirFlag) {
51 fprintf (stderr, "%s: not a directory\n", lastArg);
52
53 return (FALSE);
54 }
55
56 while (argc-- > 2) {
57 srcName = *(++argv);
58
59 if (access (srcName, 0) < 0) {
60 perror (srcName);
61 continue;
27 } 62 }
28 if ( rename(i->source, i->destination) == 0 ) 63
29 return 0; 64 destName = lastArg;
30 else if ( errno == EXDEV && is_a_directory(i->source) ) { 65
31 fprintf(stderr 66 if (dirFlag)
32 ,"%s: Can't move directory across filesystems.\n" 67 destName = buildName (destName, srcName);
33 ,i->source); 68
34 return 1; 69 if (rename (srcName, destName) >= 0)
70 continue;
71
72 if (errno != EXDEV) {
73 perror (destName);
74 continue;
35 } 75 }
36 else 76
37 return cp_fn(i); 77 if (!copyFile (srcName, destName, TRUE))
78 continue;
79
80 if (unlink (srcName) < 0)
81 perror (srcName);
82 }
83 return (TRUE);
38} 84}