summaryrefslogtreecommitdiff
path: root/libbb/copy_file.c
diff options
context:
space:
mode:
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) {