summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/untar
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2019-11-21 10:27:16 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-11-25 11:32:19 +0100
commit2de05dd58844b4ebcf9b73262e627f202bedec2d (patch)
treec14837968ae32441d22397bfeaee972bc6662f9f /cpukit/libmisc/untar
parentuntar: Unify untar support (diff)
downloadrtems-2de05dd58844b4ebcf9b73262e627f202bedec2d.tar.bz2
untar: Make path also for symbolic links
Close #3823.
Diffstat (limited to 'cpukit/libmisc/untar')
-rw-r--r--cpukit/libmisc/untar/untar.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index c6f75e3f93..ec4a5479cd 100644
--- a/cpukit/libmisc/untar/untar.c
+++ b/cpukit/libmisc/untar/untar.c
@@ -123,7 +123,7 @@ Stat_Node(const char* path)
* Make the directory path for a file if it does not exist.
*/
static int
-Make_Path(const rtems_printer *printer, const char* filename, bool end_is_dir)
+Make_Path(const rtems_printer *printer, const char* filename, int linktype)
{
char* copy = strdup(filename);
char* path = copy;
@@ -216,7 +216,7 @@ Make_Path(const rtems_printer *printer, const char* filename, bool end_is_dir)
path_end = true;
}
}
- else if (path_end && r == DIRTYPE && !end_is_dir) {
+ else if (path_end && r == DIRTYPE && linktype != DIRTYPE) {
/*
* We only handle a directory if at the end of the path and the end is
* a file. If we cannot remove the directory because it is not empty we
@@ -289,6 +289,11 @@ Untar_ProcessHeader(
* We've decoded the header, now figure out what it contains and do something
* with it.
*/
+
+ if (Make_Path(ctx->printer, ctx->file_path, ctx->linkflag) < 0) {
+ retval = UNTAR_FAIL;
+ }
+
if (ctx->linkflag == SYMTYPE) {
strlcpy(ctx->link_name, &bufr[157], sizeof(ctx->link_name));
rtems_printf(ctx->printer, "untar: symlink: %s -> %s\n",
@@ -298,15 +303,9 @@ Untar_ProcessHeader(
rtems_printf(ctx->printer, "untar: file: %s (s:%lu,m:%04lo)\n",
ctx->file_path, ctx->file_size, ctx->mode);
ctx->nblocks = (((ctx->file_size) + 511) & ~511) / 512;
- if (Make_Path(ctx->printer, ctx->file_path, false) < 0) {
- retval = UNTAR_FAIL;
- }
} else if (ctx->linkflag == DIRTYPE) {
int r;
- rtems_printf(ctx->printer, "untar: dir: %s\n", ctx->file_path);
- if (Make_Path(ctx->printer, ctx->file_path, true) < 0) {
- retval = UNTAR_FAIL;
- }
+ rtems_printf(ctx->printer, "untar: dir: %s\n", ctx->file_path);
r = mkdir(ctx->file_path, S_IRWXU | S_IRWXG | S_IRWXO);
if (r < 0) {
if (errno == EEXIST) {