aboutsummaryrefslogtreecommitdiff
path: root/libbb/copy_file.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2001-12-17 15:26:36 +0000
committerMatt Kraai <kraai@debian.org>2001-12-17 15:26:36 +0000
commitace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733 (patch)
tree1dec04901febc0fd63ac5b92bc2cca4333689477 /libbb/copy_file.c
parent46ea0e4696456061ad7ce799658f737c24f781a6 (diff)
downloadbusybox-w32-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.tar.gz
busybox-w32-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.tar.bz2
busybox-w32-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.zip
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 29778f2a4..ea05c9b8e 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -30,7 +30,7 @@
30#include <stdlib.h> 30#include <stdlib.h>
31#include <string.h> 31#include <string.h>
32 32
33#include "libbb.h" 33#include "busybox.h"
34 34
35int copy_file(const char *source, const char *dest, int flags) 35int copy_file(const char *source, const char *dest, int flags)
36{ 36{
@@ -131,6 +131,19 @@ int copy_file(const char *source, const char *dest, int flags)
131 } 131 }
132 } else if (S_ISREG(source_stat.st_mode)) { 132 } else if (S_ISREG(source_stat.st_mode)) {
133 FILE *sfp, *dfp=NULL; 133 FILE *sfp, *dfp=NULL;
134#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS
135 char *link_name;
136
137 if (!(flags & FILEUTILS_DEREFERENCE) &&
138 is_in_ino_dev_hashtable(&source_stat, &link_name)) {
139 if (link(link_name, dest) < 0) {
140 perror_msg("unable to link `%s'", dest);
141 return -1;
142 }
143
144 return 0;
145 }
146#endif
134 147
135 if ((sfp = fopen(source, "r")) == NULL) { 148 if ((sfp = fopen(source, "r")) == NULL) {
136 perror_msg("unable to open `%s'", source); 149 perror_msg("unable to open `%s'", source);
@@ -212,12 +225,21 @@ int copy_file(const char *source, const char *dest, int flags)
212 if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0) 225 if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
213 perror_msg("unable to preserve ownership of `%s'", dest); 226 perror_msg("unable to preserve ownership of `%s'", dest);
214#endif 227#endif
228
229#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS
230 add_to_ino_dev_hashtable(&source_stat, dest);
231#endif
232
215 return 0; 233 return 0;
216 } else { 234 } else {
217 error_msg("internal error: unrecognized file type"); 235 error_msg("internal error: unrecognized file type");
218 return -1; 236 return -1;
219 } 237 }
220 238
239#ifdef CONFIG_FEATURE_PRESERVE_HARDLINKS
240 add_to_ino_dev_hashtable(&source_stat, dest);
241#endif
242
221end: 243end:
222 244
223 if (flags & FILEUTILS_PRESERVE_STATUS) { 245 if (flags & FILEUTILS_PRESERVE_STATUS) {