summaryrefslogtreecommitdiff
path: root/libbb/copy_file.c
diff options
context:
space:
mode:
authorMatt Kraai2001-12-17 15:26:36 +0000
committerMatt Kraai2001-12-17 15:26:36 +0000
commitace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733 (patch)
tree1dec04901febc0fd63ac5b92bc2cca4333689477 /libbb/copy_file.c
parent46ea0e4696456061ad7ce799658f737c24f781a6 (diff)
downloadbusybox-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.zip
busybox-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.tar.gz
Make cp and mv optionally preserve hard links.
Diffstat (limited to 'libbb/copy_file.c')
-rw-r--r--libbb/copy_file.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 29778f2..ea05c9b 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -30,7 +30,7 @@
#include <stdlib.h>
#include <string.h>
-#include "libbb.h"
+#include "busybox.h"
int copy_file(const char *source, const char *dest, int flags)
{
@@ -131,6 +131,19 @@ int copy_file(const char *source, const char *dest, int flags)
}
} else if (S_ISREG(source_stat.st_mode)) {
FILE *sfp, *dfp=NULL;
+#ifdef CONFIG_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) {
+ perror_msg("unable to link `%s'", dest);
+ return -1;
+ }
+
+ return 0;
+ }
+#endif
if ((sfp = fopen(source, "r")) == NULL) {
perror_msg("unable to open `%s'", source);
@@ -212,12 +225,21 @@ int copy_file(const char *source, const char *dest, int flags)
if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
perror_msg("unable to preserve ownership of `%s'", dest);
#endif
+
+#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS
+ add_to_ino_dev_hashtable(&source_stat, dest);
+#endif
+
return 0;
} else {
error_msg("internal error: unrecognized file type");
return -1;
}
+#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS
+ add_to_ino_dev_hashtable(&source_stat, dest);
+#endif
+
end:
if (flags & FILEUTILS_PRESERVE_STATUS) {