From 88e92d59ec33c41d45b8315ef3d765a639a4ddbe Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 19 Aug 2020 18:26:07 -0500 Subject: Cleanup symlink handling. --- toys/posix/tar.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'toys/posix/tar.c') 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); -- cgit v1.2.3