X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2Flist.c;h=22bec010e475516f8a19e89d10519627c756db69;hb=ec94fbdf458adb2af803eefdd1a9c9bbb432bb21;hp=8ba07cd95490182fbd2dfa3b469ff4f9b1e17e02;hpb=df7b55a8f6354e30e8da62eec7f706df033d0c81;p=chaz%2Ftar diff --git a/src/list.c b/src/list.c index 8ba07cd..22bec01 100644 --- a/src/list.c +++ b/src/list.c @@ -1,24 +1,24 @@ /* List a tar archive, with support routines for reading a tar archive. - Copyright (C) 1988, 1992, 1993, 1994, 1996, 1997, 1998, 1999, 2000, - 2001, 2003, 2004, 2005, 2006, 2007, 2010, 2012 - Free Software Foundation, Inc. + Copyright 1988, 1992-1994, 1996-2001, 2003-2007, 2010, 2012-2014 Free + Software Foundation, Inc. - Written by John Gilmore, on 1985-08-26. + This file is part of GNU tar. - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the - Free Software Foundation; either version 3, or (at your option) any later - version. + GNU tar is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General - Public License for more details. + GNU tar is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + Written by John Gilmore, on 1985-08-26. */ #include #include @@ -115,6 +115,30 @@ transform_member_name (char **pinput, int type) return transform_name_fp (pinput, type, decode_xform, &type); } +static void +enforce_one_top_level (char **pfile_name) +{ + char *file_name = *pfile_name; + char *p; + + for (p = file_name; *p && (ISSLASH (*p) || *p == '.'); p++) + ; + + if (!*p) + return; + + if (strncmp (p, one_top_level_dir, strlen (one_top_level_dir)) == 0) + { + int pos = strlen (one_top_level_dir); + if (ISSLASH (p[pos]) || p[pos] == 0) + return; + } + + *pfile_name = new_name (one_top_level_dir, file_name); + normalize_filename_x (*pfile_name); + free (file_name); +} + void transform_stat_info (int typeflag, struct tar_stat_info *stat_info) { @@ -132,6 +156,9 @@ transform_stat_info (int typeflag, struct tar_stat_info *stat_info) case LNKTYPE: transform_member_name (&stat_info->link_name, XFORM_LINK); } + + if (one_top_level_option) + enforce_one_top_level (¤t_stat_info.file_name); } /* Main loop for reading an archive. */ @@ -176,7 +203,8 @@ read_and (void (*do_something) (void)) mtime.tv_nsec = 0, current_stat_info.mtime = mtime, OLDER_TAR_STAT_TIME (current_stat_info, m))) - || excluded_name (current_stat_info.file_name)) + || excluded_name (current_stat_info.file_name, + current_stat_info.parent)) { switch (current_header->header.typeflag) { @@ -194,6 +222,7 @@ read_and (void (*do_something) (void)) continue; } } + transform_stat_info (current_header->header.typeflag, ¤t_stat_info); (*do_something) (); @@ -660,7 +689,6 @@ decode_header (union block *header, struct tar_stat_info *stat_info, } } - stat_info->archive_file_size = stat_info->stat.st_size; xheader_decode (stat_info); if (sparse_member_p (stat_info)) @@ -723,7 +751,7 @@ from_header (char const *where0, size_t digs, char const *type, type)); return -1; } - if (!ISSPACE ((unsigned char) *where)) + if (!isspace ((unsigned char) *where)) break; where++; } @@ -861,7 +889,7 @@ from_header (char const *where0, size_t digs, char const *type, value = -value; } - if (where != lim && *where && !ISSPACE ((unsigned char) *where)) + if (where != lim && *where && !isspace ((unsigned char) *where)) { if (type) { @@ -1111,7 +1139,10 @@ simple_print_header (struct tar_stat_info *st, union block *blk, if (verbose_option <= 1) { /* Just the fax, mam. */ - fprintf (stdlis, "%s\n", quotearg (temp_name)); + fputs (quotearg (temp_name), stdlis); + if (show_transformed_names_option && st->had_trailing_slash) + fputc ('/', stdlis); + fputc ('\n', stdlis); } else { @@ -1138,9 +1169,7 @@ simple_print_header (struct tar_stat_info *st, union block *blk, case GNUTYPE_SPARSE: case REGTYPE: case AREGTYPE: - modes[0] = '-'; - if (temp_name[strlen (temp_name) - 1] == '/') - modes[0] = 'd'; + modes[0] = st->had_trailing_slash ? 'd' : '-'; break; case LNKTYPE: modes[0] = 'h'; @@ -1251,6 +1280,8 @@ simple_print_header (struct tar_stat_info *st, union block *blk, datewidth, time_stamp); fprintf (stdlis, " %s", quotearg (temp_name)); + if (show_transformed_names_option && st->had_trailing_slash) + fputc ('/', stdlis); switch (blk->header.typeflag) {