aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/tar.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2020-08-19 18:26:07 -0500
committerRob Landley <rob@landley.net>2020-08-19 18:26:07 -0500
commit88e92d59ec33c41d45b8315ef3d765a639a4ddbe (patch)
tree9900cd0579733c8b5b3238e72a3b0c3d662768c2 /toys/posix/tar.c
parent5ceee6bee1ea09f43ebe6c1fc7ae87993a1daaae (diff)
downloadtoybox-88e92d59ec33c41d45b8315ef3d765a639a4ddbe.tar.gz
Cleanup symlink handling.
Diffstat (limited to 'toys/posix/tar.c')
-rw-r--r--toys/posix/tar.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/toys/posix/tar.c b/toys/posix/tar.c
index bd738af4..9e1a4bb5 100644
--- a/toys/posix/tar.c
+++ b/toys/posix/tar.c
@@ -260,21 +260,16 @@ static int add_to_tar(struct dirtree *node)
}
} else i = 0;
- // !i because hardlink to a symlink is a thing.
- if (!i && S_ISLNK(st->st_mode)) {
- i = 2;
- }
-
// Handle file types
- if (i) {
- hdr.type = '0'+i;
- if (i==2 && !(lnk = xreadlink(name))) {
+ if (i || S_ISLNK(st->st_mode)) {
+ hdr.type = '1'+!i;
+ if (!i && !(lnk = xreadlink(name))) {
perror_msg("readlink");
goto done;
}
if (strlen(lnk) > sizeof(hdr.link)) write_longname(lnk, 'K');
strncpy(hdr.link, lnk, sizeof(hdr.link));
- if (i==2) free(lnk);
+ if (!i) free(lnk);
} else if (S_ISREG(st->st_mode)) {
hdr.type = '0';
ITOO(hdr.size, st->st_size);