diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-29 16:28:33 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-11-29 16:28:33 +0100 |
commit | d43d628f8b7e8a88a3d0160255084201e3b34955 (patch) | |
tree | 255fe5a89b15a733ca693df69e16e1900d96347c | |
parent | f94c9bf288290c9f4e5a7c2745922abd600e88ca (diff) | |
download | busybox-w32-d43d628f8b7e8a88a3d0160255084201e3b34955.tar.gz busybox-w32-d43d628f8b7e8a88a3d0160255084201e3b34955.tar.bz2 busybox-w32-d43d628f8b7e8a88a3d0160255084201e3b34955.zip |
tar: revert part of last change. -39 bytes
It looks like GNU "tar cf file file" _does_ save file as if
it is a hardlink, when it meets it for the second time.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/tar.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/archival/tar.c b/archival/tar.c index 699022ee5..c12331c83 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -136,7 +136,6 @@ static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr, | |||
136 | hlInfo->dev = statbuf->st_dev; | 136 | hlInfo->dev = statbuf->st_dev; |
137 | hlInfo->ino = statbuf->st_ino; | 137 | hlInfo->ino = statbuf->st_ino; |
138 | // hlInfo->linkCount = statbuf->st_nlink; | 138 | // hlInfo->linkCount = statbuf->st_nlink; |
139 | //TODO: "normalize" the name so that "./name/" == "name" etc? | ||
140 | strcpy(hlInfo->name, fileName); | 139 | strcpy(hlInfo->name, fileName); |
141 | } | 140 | } |
142 | 141 | ||
@@ -156,15 +155,12 @@ static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr) | |||
156 | } | 155 | } |
157 | } | 156 | } |
158 | 157 | ||
159 | /* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */ | 158 | /* Might be faster (and bigger) if the dev/ino were stored in numeric order ;) */ |
160 | static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf, const char *filename) | 159 | static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf) |
161 | { | 160 | { |
162 | while (hlInfo) { | 161 | while (hlInfo) { |
163 | if ((statbuf->st_ino == hlInfo->ino) | 162 | if (statbuf->st_ino == hlInfo->ino |
164 | && (statbuf->st_dev == hlInfo->dev) | 163 | && statbuf->st_dev == hlInfo->dev |
165 | /* Name must NOT match. Think "tar cf t.tar file file" | ||
166 | * (same file tarred twice) */ | ||
167 | && strcmp(filename, hlInfo->name) != 0 | ||
168 | ) { | 164 | ) { |
169 | DBG("found hardlink:'%s'", hlInfo->name); | 165 | DBG("found hardlink:'%s'", hlInfo->name); |
170 | break; | 166 | break; |
@@ -448,7 +444,7 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb | |||
448 | tbInfo->hlInfo = NULL; | 444 | tbInfo->hlInfo = NULL; |
449 | if (!S_ISDIR(statbuf->st_mode) && statbuf->st_nlink > 1) { | 445 | if (!S_ISDIR(statbuf->st_mode) && statbuf->st_nlink > 1) { |
450 | DBG("'%s': st_nlink > 1", header_name); | 446 | DBG("'%s': st_nlink > 1", header_name); |
451 | tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf, header_name); | 447 | tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf); |
452 | if (tbInfo->hlInfo == NULL) { | 448 | if (tbInfo->hlInfo == NULL) { |
453 | DBG("'%s': addHardLinkInfo", header_name); | 449 | DBG("'%s': addHardLinkInfo", header_name); |
454 | addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, header_name); | 450 | addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, header_name); |
@@ -627,8 +623,8 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | |||
627 | while (include) { | 623 | while (include) { |
628 | if (!recursive_action(include->data, ACTION_RECURSE | | 624 | if (!recursive_action(include->data, ACTION_RECURSE | |
629 | (dereferenceFlag ? ACTION_FOLLOWLINKS : 0), | 625 | (dereferenceFlag ? ACTION_FOLLOWLINKS : 0), |
630 | writeFileToTarball, writeFileToTarball, &tbInfo, 0)) | 626 | writeFileToTarball, writeFileToTarball, &tbInfo, 0) |
631 | { | 627 | ) { |
632 | errorFlag = TRUE; | 628 | errorFlag = TRUE; |
633 | } | 629 | } |
634 | include = include->link; | 630 | include = include->link; |
@@ -970,24 +966,21 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
970 | 966 | ||
971 | /* Open the tar file */ | 967 | /* Open the tar file */ |
972 | { | 968 | { |
973 | FILE *tar_stream; | 969 | int tar_fd = STDIN_FILENO; |
974 | int flags; | 970 | int flags = O_RDONLY; |
975 | 971 | ||
976 | if (opt & OPT_CREATE) { | 972 | if (opt & OPT_CREATE) { |
977 | /* Make sure there is at least one file to tar up. */ | 973 | /* Make sure there is at least one file to tar up. */ |
978 | if (tar_handle->accept == NULL) | 974 | if (tar_handle->accept == NULL) |
979 | bb_error_msg_and_die("empty archive"); | 975 | bb_error_msg_and_die("empty archive"); |
980 | 976 | ||
981 | tar_stream = stdout; | 977 | tar_fd = STDOUT_FILENO; |
982 | /* Mimicking GNU tar 1.15.1: */ | 978 | /* Mimicking GNU tar 1.15.1: */ |
983 | flags = O_WRONLY | O_CREAT | O_TRUNC; | 979 | flags = O_WRONLY | O_CREAT | O_TRUNC; |
984 | } else { | ||
985 | tar_stream = stdin; | ||
986 | flags = O_RDONLY; | ||
987 | } | 980 | } |
988 | 981 | ||
989 | if (LONE_DASH(tar_filename)) { | 982 | if (LONE_DASH(tar_filename)) { |
990 | tar_handle->src_fd = fileno(tar_stream); | 983 | tar_handle->src_fd = tar_fd; |
991 | tar_handle->seek = seek_by_read; | 984 | tar_handle->seek = seek_by_read; |
992 | } else { | 985 | } else { |
993 | if (ENABLE_FEATURE_TAR_AUTODETECT && flags == O_RDONLY) { | 986 | if (ENABLE_FEATURE_TAR_AUTODETECT && flags == O_RDONLY) { |