]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
Fix regression itroduced by 66162927.
authorSergey Poznyakoff <gray@gnu.org>
Sat, 16 Jan 2021 12:36:40 +0000 (14:36 +0200)
committerSergey Poznyakoff <gray@gnu.org>
Sat, 16 Jan 2021 12:38:28 +0000 (14:38 +0200)
* src/misc.c (chdir_arg): Initialize the abspath field to NULL.
(tar_getcdpath): Actually initialize the abspath field here.

src/misc.c

index c005157678d7311933bb117df4b4b88eeca22499..6819c4670d0c79ed6da4020d93e04fe2a7e6ad3b 100644 (file)
@@ -908,8 +908,6 @@ chdir_count (void)
 int
 chdir_arg (char const *dir)
 {
-  char *absdir;
-
   if (wd_count == wd_alloc)
     {
       if (wd_alloc == 0)
@@ -919,9 +917,7 @@ chdir_arg (char const *dir)
       if (! wd_count)
        {
          wd[wd_count].name = ".";
-         wd[wd_count].abspath = xgetcwd ();
-         if (!wd[wd_count].abspath)
-           call_arg_fatal ("getcwd", ".");
+         wd[wd_count].abspath = NULL;
          wd[wd_count].fd = AT_FDCWD;
          wd_count++;
        }
@@ -938,22 +934,8 @@ chdir_arg (char const *dir)
        return wd_count - 1;
     }
 
-
-  /* If the given name is absolute, use it to represent this directory;
-     otherwise, construct a name based on the previous -C option.  */
-  if (IS_ABSOLUTE_FILE_NAME (dir))
-    absdir = xstrdup (dir);
-  else if (wd[wd_count - 1].abspath)
-    {
-      namebuf_t nbuf = namebuf_create (wd[wd_count - 1].abspath);
-      namebuf_add_dir (nbuf, dir);
-      absdir = namebuf_finish (nbuf);
-    }
-  else
-    absdir = 0;
-
   wd[wd_count].name = dir;
-  wd[wd_count].abspath = absdir;
+  wd[wd_count].abspath = NULL;
   wd[wd_count].fd = 0;
   return wd_count++;
 }
@@ -1054,6 +1036,40 @@ tar_getcdpath (int idx)
        }
       return cwd;
     }
+
+  if (!wd[idx].abspath)
+    {
+      int i;
+      int save_cwdi = chdir_current;
+      
+      for (i = idx; i >= 0; i--)
+       if (wd[i].abspath)
+         break;
+      
+      while (++i <= idx)
+       {
+         chdir_do (i);
+         if (i == 0)
+           {
+             if ((wd[i].abspath = xgetcwd ()) == NULL)
+               call_arg_fatal ("getcwd", ".");
+           }
+         else if (IS_ABSOLUTE_FILE_NAME (wd[i].name))
+           /* If the given name is absolute, use it to represent this
+              directory; otherwise, construct a name based on the
+              previous -C option.  */
+           wd[i].abspath = xstrdup (wd[i].name);
+         else
+           {
+             namebuf_t nbuf = namebuf_create (wd[i - 1].abspath);
+             namebuf_add_dir (nbuf, wd[i].name);
+             wd[i].abspath = namebuf_finish (nbuf);
+           }
+       }
+
+      chdir_do (save_cwdi);
+    }
+          
   return wd[idx].abspath;
 }
 \f