From 50f604f415d77b3679df1f8d9d3856f9840998be Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 28 Feb 2021 03:37:21 -0600 Subject: Tar should remove empty directories where it wants to put a non-directory. --- toys/posix/tar.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'toys/posix/tar.c') diff --git a/toys/posix/tar.c b/toys/posix/tar.c index 66547613..f31640c5 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -485,8 +485,10 @@ 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) && errno!=ENOENT) - return perror_msg("can't remove: %s", name); + 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 (S_ISREG(ala)) { // hardlink? -- cgit v1.2.3