Another update from Larry:
[oweals/busybox.git] / mv.c
diff --git a/mv.c b/mv.c
index 13d1aae5b7067acbe47f7df9655f49a41ec055f2..b890abf6efcc89c402b3ea4df40469742e8437ec 100644 (file)
--- a/mv.c
+++ b/mv.c
 
 #include "busybox.h"
 
-static int flags = CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS;
-
-static int remove_file(const char *path, struct stat *statbuf, void *junk)
-{
-       if (unlink(path) < 0)
-               return FALSE;
-       return TRUE;
-}
-
-static int remove_directory(const char *path, struct stat *statbuf, void *junk)
-{
-       if (rmdir(path) < 0)
-               return FALSE;
-       return TRUE;
-}
+static int flags;
 
 static int manual_rename(const char *source, const char *dest)
 {
@@ -88,12 +74,11 @@ static int manual_rename(const char *source, const char *dest)
                }
        }
 
-       if (copy_file(source, dest,
-                               CP_RECUR | CP_PRESERVE_STATUS | CP_PRESERVE_SYMLINKS) < 0)
+       if (copy_file(source, dest, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS |
+                       FILEUTILS_PRESERVE_SYMLINKS) < 0)
                return -1;
 
-       if (!recursive_action(source, TRUE, FALSE, TRUE, remove_file,
-                               remove_directory, NULL))
+       if (remove_file(source, FILEUTILS_RECUR | FILEUTILS_FORCE) < 0)
                return -1;
 
        return 0;
@@ -112,9 +97,9 @@ static int move_file(const char *source, const char *dest)
                dest_exists = 0;
        }
 
-       if (dest_exists && !(flags & CP_FORCE) &&
+       if (dest_exists && !(flags & FILEUTILS_FORCE) &&
                        ((access(dest, W_OK) < 0 && isatty(0)) ||
-                        (flags & CP_INTERACTIVE))) {
+                        (flags & FILEUTILS_INTERACTIVE))) {
                fprintf(stderr, "mv: overwrite `%s'? ", dest);
                if (!ask_confirmation())
                        return 0;
@@ -140,12 +125,12 @@ extern int mv_main(int argc, char **argv)
        while ((opt = getopt(argc, argv, "fi")) != -1)
                switch (opt) {
                case 'f':
-                       flags &= ~CP_INTERACTIVE;
-                       flags |= CP_FORCE;
+                       flags &= ~FILEUTILS_INTERACTIVE;
+                       flags |= FILEUTILS_FORCE;
                        break;
                case 'i':
-                       flags &= ~CP_FORCE;
-                       flags |= CP_INTERACTIVE;
+                       flags &= ~FILEUTILS_FORCE;
+                       flags |= FILEUTILS_INTERACTIVE;
                        break;
                default:
                        show_usage();