aboutsummaryrefslogtreecommitdiff
path: root/toys/posix
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2021-02-28 03:37:21 -0600
committerRob Landley <rob@landley.net>2021-02-28 03:37:21 -0600
commit50f604f415d77b3679df1f8d9d3856f9840998be (patch)
treebd4e5d5032d28fac5be99f7cc92b2936977f4bbc /toys/posix
parent1ba53eead1ab9787e77dc43196b8402ec96e7fd4 (diff)
downloadtoybox-50f604f415d77b3679df1f8d9d3856f9840998be.tar.gz
Tar should remove empty directories where it wants to put a non-directory.
Diffstat (limited to 'toys/posix')
-rw-r--r--toys/posix/tar.c6
1 files changed, 4 insertions, 2 deletions
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?