[rtems commit] untar: Make path also for symbolic links

Sebastian Huber sebh at rtems.org
Mon Nov 25 10:45:28 UTC 2019


Module:    rtems
Branch:    master
Commit:    2de05dd58844b4ebcf9b73262e627f202bedec2d
Changeset: http://git.rtems.org/rtems/commit/?id=2de05dd58844b4ebcf9b73262e627f202bedec2d

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Nov 21 10:27:16 2019 +0100

untar: Make path also for symbolic links

Close #3823.

---

 cpukit/libmisc/untar/untar.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/cpukit/libmisc/untar/untar.c b/cpukit/libmisc/untar/untar.c
index c6f75e3..ec4a547 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) {



More information about the vc mailing list