From a3b423c58e6f67131ef5f1874fc6bd38880322b6 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 16 Sep 2021 23:01:34 -0500 Subject: [PATCH] The Linux errno from unlink(dir) defies posix and this bothers some people, so don't depend on it. --- toys/posix/tar.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/toys/posix/tar.c b/toys/posix/tar.c index f2a6cdb6..bd68873c 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -529,10 +529,8 @@ static void extract_to_disk(void) return perror_msg(":%s: can't mkdir", name); // remove old file, if exists - if (!FLAG(k) && !S_ISDIR(ala) && unlink(name)) { - if (errno==EISDIR && !rmdir(name)); - else if (errno!=ENOENT) return perror_msg("can't remove: %s", name); - } + if (!FLAG(k) && !S_ISDIR(ala) && rmdir(name) && errno!=ENOENT && unlink(name)) + return perror_msg("can't remove: %s", name); if (S_ISREG(ala)) { // hardlink? -- 2.39.2