From 0f8ddede4768c96e5cdef812719f228d13a16682 Mon Sep 17 00:00:00 2001 From: Brett Gordon Date: Sun, 8 Apr 2018 12:41:29 -0400 Subject: [PATCH] tar: make parent directories --- Applications/util/tar.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Applications/util/tar.c b/Applications/util/tar.c index 40a5fd64..68151dc1 100644 --- a/Applications/util/tar.c +++ b/Applications/util/tar.c @@ -435,6 +435,23 @@ static void list(void) } /* block while */ } +/* Attempt to make all parent directories */ +static void makeparents(char *path) +{ + static char c[100]; + char *s = path; + int l; + while (1){ + char *e = index(s,'/'); + if (!e) + return; + l = e - path; + memcpy(c,path,l); + c[l] = 0; + mkdir(c,0755); + s = e + 1; + } +} /* Extract all file in archive */ static void extract(char *argv[]) @@ -494,6 +511,8 @@ static void extract(char *argv[]) uflag = !strncmp(h.ustar, "ustar", 5); + makeparents(h.name); + switch (h.type) { case '1': /* a hard link */ x = link(h.lname, h.name); -- 2.34.1