svn commit: trunk/busybox/libbb

landley at busybox.net landley at busybox.net
Sat Jun 24 21:27:39 UTC 2006


Author: landley
Date: 2006-06-24 14:27:36 -0700 (Sat, 24 Jun 2006)
New Revision: 15501

Log:
The logic to make cp -d or -P treat things like regular files should only
trigger for symlinks, not for device nodes.  This should fix "cp -a /dev ."
to work as expected (when run by root, anyway).

While I was there, cleanup headers and make an #ifdef go away...


Modified:
   trunk/busybox/libbb/copy_file.c


Changeset:
Modified: trunk/busybox/libbb/copy_file.c
===================================================================
--- trunk/busybox/libbb/copy_file.c	2006-06-24 17:55:02 UTC (rev 15500)
+++ trunk/busybox/libbb/copy_file.c	2006-06-24 21:27:36 UTC (rev 15501)
@@ -8,18 +8,10 @@
  *
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
+#include "libbb.h"
 #include <utime.h>
 #include <errno.h>
-#include <dirent.h>
-#include <stdlib.h>
-#include <string.h>
 
-#include "libbb.h"
-
 int copy_file(const char *source, const char *dest, int flags)
 {
 	struct stat source_stat;
@@ -110,24 +102,25 @@
 			bb_perror_msg("unable to change permissions of `%s'", dest);
 			status = -1;
 		}
-	} else if (S_ISREG(source_stat.st_mode) || (flags & FILEUTILS_DEREFERENCE))
+	} else if (S_ISREG(source_stat.st_mode) ||
+		   (S_ISLNK(source_stat.st_mode) && (flags & FILEUTILS_DEREFERENCE)))
 	{
 		int src_fd;
 		int dst_fd;
-#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS
-		char *link_name;
+		if (ENABLE_FEATURE_PRESERVE_HARDLINKS) {
+			char *link_name;
 
-		if (!(flags & FILEUTILS_DEREFERENCE) &&
-				is_in_ino_dev_hashtable(&source_stat, &link_name)) {
-			if (link(link_name, dest) < 0) {
-				bb_perror_msg("unable to link `%s'", dest);
-				return -1;
-			}
+			if (!(flags & FILEUTILS_DEREFERENCE) &&
+					is_in_ino_dev_hashtable(&source_stat, &link_name)) {
+				if (link(link_name, dest) < 0) {
+					bb_perror_msg("unable to link `%s'", dest);
+					return -1;
+				}
 
-			return 0;
+				return 0;
+			}
+			add_to_ino_dev_hashtable(&source_stat, dest);
 		}
-		add_to_ino_dev_hashtable(&source_stat, dest);
-#endif
 		src_fd = open(source, O_RDONLY);
 		if (src_fd == -1) {
 			bb_perror_msg("unable to open `%s'", source);




More information about the busybox-cvs mailing list