diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-01-16 14:36:40 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-01-16 14:38:28 +0200 |
commit | 972bebf07e7ec6a259efca9ed58c3b8ca121ea6e (patch) | |
tree | 5b521fbedd7285c3a5ca7b6fe7c10244e0893cb1 | |
parent | 8e2898ab11f687aefb4d1deb9f27295e6a1080a1 (diff) | |
download | tar-972bebf07e7ec6a259efca9ed58c3b8ca121ea6e.tar.gz |
Fix regression itroduced by 66162927.
* src/misc.c (chdir_arg): Initialize the abspath field to NULL.
(tar_getcdpath): Actually initialize the abspath field here.
-rw-r--r-- | src/misc.c | 56 |
1 files changed, 36 insertions, 20 deletions
@@ -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; } |