]> Dogcows Code - chaz/tar/commitdiff
Optimize searches for directory structures by keeping a pointer to struct directory...
authorSergey Poznyakoff <gray@gnu.org.ua>
Sat, 8 Aug 2009 10:16:53 +0000 (13:16 +0300)
committerSergey Poznyakoff <gray@gnu.org.ua>
Sat, 8 Aug 2009 12:29:19 +0000 (15:29 +0300)
* src/common.h (struct name): New member `directory' replaces
dir_contents. Rearrange members.
(rebase_directory): Change signature.
(scan_directory): Change signature.
(name_fill_directory)
(directory_contents, safe_directory_contents): New prototypes.
(append_incremental_renames): Change signature.
(replace_prefix): New proto.
* src/compare.c (diff_dumpdir): Use directory_contents + scan_directory.
* src/create.c
* src/incremen.c (replace_prefix): Move to misc.c
(rebase_directory): Rewrite.
(scan_directory): Return pointer to struct directory.
(directory_contents, safe_directory_contents): New functions.
(get_directory_contents): Remove.
(name_fill_directory): New function.
(append_incremental_renames): Rewrite. This also fixes a memory leak.
* src/names.c (name_gather, addname): Reflect changes in struct name.
(add_hierarchy_to_namelist): Rewrite using name_fill_directory and
directory_contents.
(rebase_child_list): Update call to rebase_directory.
(collect_and_sort_names): Optimize

* src/misc.c (replace_prefix): New function.
* src/names.c (add_hierarchy_to_namelist): Use new get_directory_contents.

* tests/incr05.at: New test case.
* tests/incr06.at: New test case.
* tests/Makefile.am, test/testsuite.at: Add incr05.at and incr06.at.

* doc/Makefile.am (check-options): Improve rule.
* doc/tar.texi, NEWS: Update.

13 files changed:
NEWS
doc/Makefile.am
doc/tar.texi
src/common.h
src/compare.c
src/create.c
src/incremen.c
src/misc.c
src/names.c
tests/Makefile.am
tests/incr05.at [new file with mode: 0644]
tests/incr06.at [new file with mode: 0644]
tests/testsuite.at

diff --git a/NEWS b/NEWS
index 4dba114020cb77dfd6e38f147ae556781b997e78..352f5a27839d81c71cc8f8e261f514d536c02809 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU tar NEWS - User visible changes. 2009-08-05
+GNU tar NEWS - User visible changes. 2009-08-08
 Please send GNU tar bug reports to <bug-tar@gnu.org>
 
 \f
@@ -23,6 +23,14 @@ messages are suppressed.  For example,
 suppresses the output of `A lone zero block' diagnostics, which is
 normally issued if `archive' ends with a single block of zeros.
 
+* New command line option `--level'
+
+The `--level=N' option sets the incremental dump level N.  It
+is valid when used in conjunction with the -c and --listed-incremental
+options.  So far the only meaningful value for N is 0.  The
+`--level=0' option forces creating the level 0 dump, by truncating
+the snapshot file if it exists.
+
 * Bugfixes
 ** Fix handling of hard link targets by -c --transform.
 ** Fix hard links recognition with -c --remove-files.
index 1715d3566b9bd38dd6d110e822dfd0a5cb76e83c..ec771ca2908748fd094d81e6efa8e2b19b18b288 100644 (file)
@@ -59,25 +59,28 @@ check-format:
        fi
 
 check-options:
-       @ARGP_HELP_FMT='usage-indent=0,short-opt-col=0,long-opt-col=0,\
-doc-opt-col=0,opt-doc-col=0,header-col=0,rmargin=1' \
+       @ARGP_HELP_FMT='usage-indent=0,short-opt-col=0,long-opt-col=0,doc-opt-col=0,opt-doc-col=0,header-col=0,rmargin=1' \
        $(top_builddir)/src/tar --usage | \
        sed -n 's/^\[--\([^]\=\[]*\).*/\1/p' | sort | uniq > opts.$$$$;\
        $(MAKEINFO) $(AM_MAKEINFOFLAGS) $(MAKEINFOFLAGS) -I $(srcdir) -E - \
             $(info_TEXINFOS) | \
        sed -n '/^@macro/,/^@end macro/d;s/@opindex *\([^@,]*\).*/\1/p' \
             | sort | uniq > docs.$$$$;\
-       (echo 'Not documented options:';\
-        join -v1 opts.$$$$ docs.$$$$;\
-        echo 'Non-existing options:';\
-        join -v2 opts.$$$$ docs.$$$$) > report.$$$$;\
-        rm opts.$$$$ docs.$$$$;\
-        if [ -n "`sed '1,2d' report.$$$$`" ]; then \
-          cat report.$$$$;\
-          rm report.$$$$;\
-          exit 1;\
-        fi;\
-        rm report.$$$$
+       status=0;\
+       join -v1 opts.$$$$ docs.$$$$ > report.$$$$;\
+       if test -s report.$$$$; then \
+          echo 'Not documented options:'; \
+          cat report.$$$$; \
+          status=1; \
+        fi; \
+       join -v2 opts.$$$$ docs.$$$$ > report.$$$$;\
+       if test -s report.$$$$; then \
+         echo 'Non-existing options:';\
+          cat report.$$$$; \
+          status=1; \
+        fi; \
+       rm opts.$$$$ docs.$$$$ report.$$$$;\
+       test $$status -ne 0 && exit $$status
 
 check-refs:
        @for file in $(info_TEXINFOS) $(tar_TEXINFOS); \
index a613d6b8867f64a49079111c9b038a3ef6a448ea..fdee5b5d42ab095681fc58d37ea8f6501c1643a3 100644 (file)
@@ -1519,7 +1519,6 @@ all the files (including sub-directories) in that directory.
 
 @node extract
 @section How to Extract Members from an Archive
-@UNREVISED
 @cindex Extraction
 @cindex Retrieving files from an archive
 @cindex Resurrecting files from an archive
@@ -1771,7 +1770,6 @@ be in the rest of the manual.}
 
 @node tar invocation
 @chapter Invoking @GNUTAR{}
-@UNREVISED
 
 This chapter is about how one invokes the @GNUTAR{}
 command, from the command synopsis (@pxref{Synopsis}).  There are
@@ -2010,6 +2008,10 @@ attention to them.
 @node Long Options
 @subsection Long Option Style
 
+@cindex long options
+@cindex options, long style
+@cindex options, GNU style
+@cindex options, mnemonic names
 Each option has at least one @dfn{long} (or @dfn{mnemonic}) name starting with two
 dashes in a row, e.g., @option{--list}.  The long names are more clear than
 their corresponding short or old names.  It sometimes happens that a
@@ -2038,6 +2040,8 @@ $ @kbd{tar --create --verbose --blocking-factor=20 --file=/dev/rmt0}
 gives a fairly good set of hints about what the command does, even
 for those not fully acquainted with @command{tar}.
 
+@cindex arguments to long options
+@cindex long options with mandatory arguments
 Long options which require arguments take those arguments
 immediately following the option name.  There are two ways of
 specifying a mandatory argument.  It can be separated from the
@@ -2047,6 +2051,8 @@ tells the name of the @command{tar} archive) is given a file such as
 @file{archive.tar} as argument by using any of the following notations:
 @option{--file=archive.tar} or @option{--file archive.tar}.
 
+@cindex optional arguments to long options
+@cindex long options with optional arguments
 In contrast, optional arguments must always be introduced using
 an equal sign.  For example, the @option{--backup} option takes
 an optional argument specifying backup type.  It must be used
@@ -2055,6 +2061,9 @@ as @option{--backup=@var{backup-type}}.
 @node Short Options
 @subsection Short Option Style
 
+@cindex short options
+@cindex options, short style
+@cindex options, traditional
 Most options also have a @dfn{short option} name.  Short options start with
 a single dash, and are followed by a single character, e.g., @option{-t}
 (which is equivalent to @option{--list}).  The forms are absolutely
@@ -2062,6 +2071,8 @@ identical in function; they are interchangeable.
 
 The short option names are faster to type than long option names.
 
+@cindex arguments to short options
+@cindex short options with mandatory arguments
 Short options which require arguments take their arguments immediately
 following the option, usually separated by white space.  It is also
 possible to stick the argument right after the short option name, using
@@ -2071,6 +2082,8 @@ archive.tar}} or @option{-farchive.tar} instead of using
 @w{@option{-f @var{archive-name}}} denote the option which indicates a
 specific archive, here named @file{archive.tar}.
 
+@cindex optional arguments to short options
+@cindex short options with optional arguments
 Short options which take optional arguments take their arguments
 immediately following the option letter, @emph{without any intervening
 white space characters}.
@@ -2098,7 +2111,8 @@ end up overwriting files.
 
 @node Old Options
 @subsection Old Option Style
-@UNREVISED
+@cindex options, old style
+@cindex old option style
 
 Like short options, @dfn{old options} are single letters.  However, old options
 must be written together as a single clumped set, without spaces separating
@@ -2113,6 +2127,8 @@ the same as the short option @option{-t}, and consequently, the same as the
 long option @option{--list}.  So for example, the command @w{@samp{tar
 cv}} specifies the option @option{-v} in addition to the operation @option{-c}.
 
+@cindex arguments to old options
+@cindex old options with mandatory arguments
 When options that need arguments are given together with the command,
 all the associated arguments follow, in the same order as the options.
 Thus, the example given previously could also be written in the old
@@ -2176,6 +2192,7 @@ equivalent to @w{@samp{tar -c}:} both of them specify the
 @node Mixing
 @subsection Mixing Option Styles
 
+@cindex options, mixing different styles
 All three styles may be intermixed in a single @command{tar} command,
 so long as the rules for each style are fully
 respected@footnote{Before @GNUTAR{} version 1.11.6,
@@ -2777,6 +2794,17 @@ as a name record in the archive.  When extracting or listing archives,
 @command{tar} will only operate on archives that have a label matching
 the pattern specified in @var{name}.  @xref{Tape Files}.
 
+@opsummary{level}
+@item --level=@var{n}
+Force incremental backup of level @var{n}.  As of @GNUTAR version
+@value{VERSION}, the option @option{--level=0} truncates the snapshot
+file, thereby forcing the level 0 dump.  Other values of @var{n} are
+effectively ignored.  @xref{--level=0}, for details and examples.
+
+The use of this option is valid only in conjunction with the
+@option{--listed-incremental} option.  @xref{Incremental Dumps},
+for a detailed description.
+
 @opsummary{listed-incremental}
 @item --listed-incremental=@var{snapshot-file}
 @itemx -g @var{snapshot-file}
@@ -4074,7 +4102,7 @@ Disable all warning messages.
 @samp{Current %s is newer or same age}
 @kwindex unknown-keyword
 @cindex @samp{Ignoring unknown extended header keyword `%s'}, warning message
-@item unknown-keyword          
+@item unknown-keyword           
 @samp{Ignoring unknown extended header keyword `%s'}
 @end table
 
@@ -4258,8 +4286,8 @@ it still introduces the info in the chapter correctly : ).}
 
 @node Operations
 @subsection The Five Advanced @command{tar} Operations
-@UNREVISED
 
+@cindex basic operations
 In the last chapter, you learned about the first three operations to
 @command{tar}.  This chapter presents the remaining five operations to
 @command{tar}: @option{--append}, @option{--update}, @option{--concatenate},
@@ -4309,8 +4337,8 @@ Compare archive members to their counterparts in the file system.
 
 @node append
 @subsection How to Add Files to Existing Archives: @option{--append}
-@UNREVISED
 
+@cindex appending files to existing archive
 @opindex append
 If you want to add files to an existing archive, you don't need to
 create a new archive; you can use @option{--append} (@option{-r}).
@@ -4343,6 +4371,8 @@ the one in the archive and you invoke @command{tar} with
 member will end up being extracted, as it will replace the one
 extracted before it, and so on.
 
+@cindex extracting @var{n}th copy of the file
+@xopindex{occurrence, described}
 There exists a special option that allows you to get around this
 behavior and extract (or list) only a particular copy of the file.
 This is @option{--occurrence} option.  If you run @command{tar} with
@@ -4369,8 +4399,9 @@ with the Same Name.}
 
 @cindex Members, replacing with other members
 @cindex Replacing members with other members
+@xopindex{delete, using before --append}
 If you want to replace an archive member, use @option{--delete} to
-delete the member you want to remove from the archive, and then use
+delete the member you want to remove from the archive, and then use
 @option{--append} to add the member you want to be in the archive.  Note
 that you can not change the order of the archive; the most recently
 added member will still appear last.  In this sense, you cannot truly
@@ -4385,10 +4416,10 @@ and @ref{Media}, for more information.)
 
 @node appending files
 @subsubsection Appending Files to an Archive
-@UNREVISED
 @cindex Adding files to an Archive
 @cindex Appending files to an Archive
 @cindex Archives, Appending files to
+@opindex append
 
 The simplest way to add a file to an already existing archive is the
 @option{--append} (@option{-r}) operation, which writes specified
@@ -4432,6 +4463,8 @@ $ @kbd{tar --list --file=collection.tar}
 
 @node multiple
 @subsubsection Multiple Members with the Same Name
+@cindex members, multiple
+@cindex multiple members
 
 You can use @option{--append} (@option{-r}) to add copies of files
 which have been updated since the archive was created.  (However, we
@@ -4498,10 +4531,9 @@ $ @kbd{tar --extract -vv --occurrence --file=collection.tar blues}
 
 @node update
 @subsection Updating an Archive
-@UNREVISED
 @cindex Updating an archive
-
 @opindex update
+
 In the previous section, you learned how to use @option{--append} to
 add a file to an existing archive.  A related operation is
 @option{--update} (@option{-u}).  The @option{--update} operation
@@ -4528,6 +4560,7 @@ the @option{--backup} option.  @xref{multiple}, for a detailed discussion.
 
 @node how to update
 @subsubsection How to Update an Archive Using @option{--update}
+@opindex update
 
 You must use file name arguments with the @option{--update}
 (@option{-u}) operation.  If you don't specify any files,
@@ -4669,7 +4702,6 @@ information on dealing with archives improperly combined using the
 
 @node delete
 @subsection Removing Archive Members Using @option{--delete}
-@UNREVISED
 @cindex Deleting files from an archive
 @cindex Removing files from an archive
 
@@ -4724,7 +4756,6 @@ The @option{--delete} option has been reported to work properly when
 @node compare
 @subsection Comparing Archive Members with the File System
 @cindex Verifying the currency of an archive
-@UNREVISED
 
 @opindex compare
 The @option{--compare} (@option{-d}), or @option{--diff} operation compares
@@ -4879,7 +4910,7 @@ Do not exit with nonzero on unreadable files or directories.
 
 @node extract options
 @section Options Used by @option{--extract}
-@UNREVISED
+@cindex options for use with @option{--extract}
 
 @xopindex{extract, additional options}
 The previous chapter showed how to use @option{--extract} to extract
@@ -4900,7 +4931,6 @@ considerations arise.  You may review the information presented in
 @node Reading
 @subsection Options to Help Read Archives
 @cindex Options when reading archives
-@UNREVISED
 
 @cindex Reading incomplete records
 @cindex Records, incomplete
@@ -5645,25 +5675,18 @@ and not archive them.  @xref{Choosing}.
 
 @node Backups
 @chapter Performing Backups and Restoring Files
-@UNREVISED
+@cindex backups
 
-@GNUTAR{} is distributed along with the scripts
-which the Free Software Foundation uses for performing backups.  There
-is no corresponding scripts available yet for doing restoration of
-files.  Even if there is a good chance those scripts may be satisfying
-to you, they are not the only scripts or methods available for doing
+@GNUTAR{} is distributed along with the scripts for performing backups
+and restores.  Even if there is a good chance those scripts may be
+satisfying to you, they are not the only scripts or methods available for doing
 backups and restore.  You may well create your own, or use more
 sophisticated packages dedicated to that purpose.
 
 Some users are enthusiastic about @code{Amanda} (The Advanced Maryland
 Automatic Network Disk Archiver), a backup system developed by James
 da Silva @file{jds@@cs.umd.edu} and available on many Unix systems.
-This is free software, and it is available at these places:
-
-@smallexample
-http://www.cs.umd.edu/projects/amanda/amanda.html
-ftp://ftp.cs.umd.edu/pub/amanda
-@end smallexample
+This is free software, and it is available from @uref{http://www.amanda.org}. 
 
 @FIXME{
 
@@ -5783,7 +5806,7 @@ can be restored when extracting the archive.
 backups: @option{--listed-incremental=@var{snapshot-file}} (@option{-g
 @var{snapshot-file}}) and @option{--incremental} (@option{-G}).
 
-@opindex listed-incremental
+@xopindex{listed-incremental, described}
 The option @option{--listed-incremental} instructs tar to operate on
 an incremental archive with additional metadata stored in a standalone
 file, called a @dfn{snapshot file}.  The purpose of this file is to help
@@ -5857,6 +5880,20 @@ $ @kbd{tar --create \
            /usr}
 @end smallexample
 
+@anchor{--level=0}
+@xopindex{level, described}
+You can force @samp{level 0} backups either by removing the snapshot
+file before running @command{tar}, or by supplying the
+@option{--level=0} option, e.g.:
+
+@smallexample
+$ @kbd{tar --create \
+           --file=archive.2.tar \
+           --listed-incremental=/var/log/usr.snar-0 \
+           --level=0 \
+           /usr}
+@end smallexample
+
 Incremental dumps depend crucially on time stamps, so the results are
 unreliable if you modify a file's time stamps during dumping (e.g.,
 with the @option{--atime-preserve=replace} option), or if you set the clock
@@ -6540,7 +6577,6 @@ that determination.
 
 @node Choosing
 @chapter Choosing Files and Names for @command{tar}
-@UNREVISED
 
 Certain options to @command{tar} enable you to specify a name for your
 archive.  Other options let you decide which files to include or exclude
@@ -6565,12 +6601,12 @@ This chapter discusses these options in detail.
 
 @node file
 @section Choosing and Naming Archive Files
-@UNREVISED
 
 @cindex Naming an archive
 @cindex Archive Name
 @cindex Choosing an archive file
 @cindex Where is the archive?
+@opindex file
 By default, @command{tar} uses an archive file name that was compiled when
 it was built on the system; usually this name refers to some physical
 tape drive on the machine.  However, the person who installed @command{tar}
@@ -6773,6 +6809,7 @@ of files and archive members.
 @cindex Reading file names from a file
 @cindex Lists of file names
 @cindex File Name arguments, alternatives
+@cindex @command{find}, using with @command{tar}
 Instead of giving the names of files or archive members on the command
 line, you can put the names into a file, and then use the
 @option{--files-from=@var{file-of-names}} (@option{-T
@@ -6974,11 +7011,12 @@ to these eventual surplus @option{-T} options as well.
 
 @node exclude
 @section Excluding Some Files
-@UNREVISED
 
 @cindex File names, excluding files by
 @cindex Excluding files by name and pattern
 @cindex Excluding files by file system
+@opindex exclude
+@opindex exclude-from
 To avoid operating on files whose names match a particular pattern,
 use the @option{--exclude} or @option{--exclude-from} options.
 
@@ -8003,7 +8041,6 @@ $ @kbd{tar -cf arch.tar \
 
 @node after
 @section Operating Only on New Files
-@UNREVISED
 
 @cindex Excluding file by age
 @cindex Data Modification time, excluding files by
@@ -8023,6 +8060,8 @@ If you only want @command{tar} to make the date comparison based on
 modification of the file's data (rather than status
 changes), then use the @option{--newer-mtime=@var{date}} option.
 
+@cindex --after-date and --update compared
+@cindex --newer-mtime and --update compared
 You may use these options with any operation.  Note that these options
 differ from the @option{--update} (@option{-u}) operation in that they
 allow you to specify a particular date against which @command{tar} can
@@ -8099,27 +8138,26 @@ for proper way of creating incremental backups.
 
 @node recurse
 @section Descending into Directories
-@UNREVISED
 @cindex Avoiding recursion in directories
 @cindex Descending directories, avoiding
 @cindex Directories, avoiding recursion
 @cindex Recursion in directories, avoiding
 
-@FIXME{arrggh!  this is still somewhat confusing to me. :-< }
-
 Usually, @command{tar} will recursively explore all directories (either
 those given on the command line or through the @option{--files-from}
 option) for the various files they contain.  However, you may not always
 want @command{tar} to act this way.
 
 @opindex no-recursion
+@cindex @command{find}, using with @command{tar}
 The @option{--no-recursion} option inhibits @command{tar}'s recursive descent
 into specified directories.  If you specify @option{--no-recursion}, you can
-use the @command{find} utility for hunting through levels of directories to
+use the @command{find} (@pxref{Top,, find, find, GNU Find Manual})
+utility for hunting through levels of directories to
 construct a list of file names which you could then pass to @command{tar}.
 @command{find} allows you to be more selective when choosing which files to
 archive; see @ref{files}, for more information on using @command{find} with
-@command{tar}, or look.
+@command{tar}.
 
 @table @option
 @item --no-recursion
@@ -8180,7 +8218,6 @@ other than @file{grape/concord}.
 @node one
 @section Crossing File System Boundaries
 @cindex File system boundaries, not crossing
-@UNREVISED
 
 @command{tar} will normally automatically cross file system boundaries in
 order to archive files which are part of a directory tree.  You can
@@ -8321,7 +8358,12 @@ The interpretation of @option{--directory} is disabled by
 
 @node absolute
 @subsection Absolute File Names
-@UNREVISED
+@cindex absolute file names
+@cindex file names, absolute
+
+By default, @GNUTAR{} drops a leading @samp{/} on
+input or output, and complains about file names containing a @file{..}
+component.  There is an option that turns off this behavior:
 
 @table @option
 @opindex absolute-names
@@ -8331,10 +8373,6 @@ Do not strip leading slashes from file names, and permit file names
 containing a @file{..} file name component.
 @end table
 
-By default, @GNUTAR{} drops a leading @samp{/} on
-input or output, and complains about file names containing a @file{..}
-component.  This option turns off this behavior.
-
 When @command{tar} extracts archive members from an archive, it strips any
 leading slashes (@samp{/}) from the member name.  This causes absolute
 member names in the archive to be treated as relative file names.  This
@@ -8382,8 +8420,6 @@ may be more convenient than switching to root.
 @FIXME{Should be an example in the tutorial/wizardry section using this
 to transfer files between systems.}
 
-@FIXME{Is write access an issue?}
-
 @table @option
 @item --absolute-names
 Preserves full file names (including superior directory names) when
@@ -8391,8 +8427,6 @@ archiving files.  Preserves leading slash when extracting files.
 
 @end table
 
-@FIXME{this is still horrible; need to talk with dan on monday.}
-
 @command{tar} prints out a message about removing the @samp{/} from
 file names.  This message appears once per @GNUTAR{}
 invocation.  It represents something which ought to be told; ignoring
@@ -8917,15 +8951,14 @@ Using @option{--sparse-format} option implies @option{--sparse}.
 
 @node Attributes
 @section Handling File Attributes
-@UNREVISED
+@cindex atrributes, files
+@cindex file attributes
 
 When @command{tar} reads files, it updates their access times.  To
 avoid this, use the @option{--atime-preserve[=METHOD]} option, which can either
 reset the access time retroactively or avoid changing it in the first
 place.
 
-Handling of file attributes
-
 @table @option
 @opindex atime-preserve
 @item --atime-preserve
@@ -9134,7 +9167,6 @@ it contains unresolved symbolic links.
 
 @node hard links
 @subsection Hard Links
-@UNREVISED{}
 @cindex File names, using hard links
 @cindex hard links, dereferencing
 @cindex dereferencing hard links
@@ -9466,7 +9498,7 @@ a @command{tar} able to read the good archives they receive.
 @cindex large values
 @cindex future time stamps
 @cindex negative time stamps
-@UNREVISED{}
+@UNREVISED
 
 The above sections suggest to use @samp{oldest possible} archive
 format if in doubt.  However, sometimes it is not possible.  If you
@@ -10227,7 +10259,8 @@ device busy
 
 @node Blocking
 @section Blocking
-@UNREVISED
+@cindex block
+@cindex record
 
 @dfn{Block} and @dfn{record} terminology is rather confused, and it
 is also confusing to the expert reader.  On the other hand, readers
@@ -10821,8 +10854,6 @@ Prints status information about the tape unit.
 
 @end table
 
-@FIXME{Is there a better way to frob the spacing on the list?}
-
 If you don't specify a @var{tapename}, @command{mt} uses the environment
 variable @env{TAPE}; if @env{TAPE} is not set, @command{mt} will use
 the default device specified in your @file{sys/mtio.h} file
@@ -11139,6 +11170,8 @@ implementation, read @ref{Split Recovery}.
 
 @node Tape Files
 @subsection Tape Files
+@cindex labeling archives
+@opindex label
 @UNREVISED
 
 To give the archive a name which will be recorded in it, use the
@@ -11488,10 +11521,7 @@ up to and including 1.8.4 invoke tar with this option to produce
 distribution tarballs.  @xref{Formats,v7}, for the detailed discussion
 of this issue and its implications.
 
-@FIXME{Change the first argument to tar-formats when the new Automake is
-out. The proposition to add @anchor{} to the appropriate place of its
-docs was accepted by Automake people  --Sergey 2006-05-25}.
-@xref{Options, tar-v7, Changing Automake's Behavior,
+@xref{Options, tar-formats, Changing Automake's Behavior,
 automake, GNU Automake}, for a description on how to use various
 archive formats with @command{automake}.
 
index 9905817d5cce4115e5dc5dcadd06d0490df9ac64..59de8a9e50525a10597e9e677ac67eeadcff4a99 100644 (file)
@@ -320,26 +320,32 @@ GLOBAL const char **archive_name_cursor;
 /* Output index file name.  */
 GLOBAL char const *index_file_name;
 
+/* Opaque structure for keeping directory meta-data */
+struct directory;
+
 /* Structure for keeping track of filenames and lists thereof.  */
 struct name
   {
     struct name *next;          /* Link to the next element */
     struct name *prev;          /* Link to the previous element */
+
+    char *name;                 /* File name or globbing pattern */
+    size_t length;             /* cached strlen (name) */
+    int matching_flags;                /* wildcard flags if name is a pattern */
+
     int change_dir;            /* Number of the directory to change to.
                                   Set with the -C option. */
     uintmax_t found_count;     /* number of times a matching file has
                                   been found */
-    int matching_flags;                /* this name is a regexp, not literal */
     
-    size_t length;             /* cached strlen(name) */
-    char *name;
-
-    /* The following members are used for incremental dumps only */
-    char const *dir_contents;  /* directory contents  */
+    /* The following members are used for incremental dumps only,
+       if this struct name represents a directory;
+       see incremen.c */
+    struct directory *directory;/* directory meta-data and contents */
     struct name *parent;        /* pointer to the parent hierarchy */
     struct name *child;         /* pointer to the first child */
     struct name *sibling;       /* pointer to the next sibling */
-    char *caname;               /* canonical name */ 
+    char *caname;               /* canonical name */
   };
 
 /* Obnoxious test to see if dimwit is trying to dump the archive.  */
@@ -505,16 +511,21 @@ char *dumpdir_locate (dumpdir_t dump, const char *name);
 char *dumpdir_next (dumpdir_iter_t itr);
 char *dumpdir_first (dumpdir_t dump, int all, dumpdir_iter_t *pitr);
 
-const char *scan_directory (char *dir_name, dev_t device, bool cmdline);
-const char *append_incremental_renames (const char *dump);
+struct directory *scan_directory (char *dir, dev_t device, bool cmdline);
+void name_fill_directory (struct name *name, dev_t device, bool cmdline);
+const char *directory_contents (struct directory *dir);
+const char *safe_directory_contents (struct directory *dir);
+
+void rebase_directory (struct directory *dir,
+                      const char *samp, size_t slen,
+                      const char *repl, size_t rlen);
+
+void append_incremental_renames (struct directory *dir);
 void read_directory_file (void);
 void write_directory_file (void);
 void purge_directory (char const *directory_name);
 void list_dumpdir (char *buffer, size_t size);
 void update_parent_directory (const char *name);
-void rebase_directory (const char *name, size_t old_prefix_len,
-                      const char *old_prefix,
-                      const char *new_prefix);
 
 size_t dumpdir_size (const char *p);
 bool is_dumpdir (struct tar_stat_info *stat_info);
@@ -558,7 +569,7 @@ off_t off_from_header (const char *buf, size_t size);
 size_t size_from_header (const char *buf, size_t size);
 time_t time_from_header (const char *buf, size_t size);
 uid_t uid_from_header (const char *buf, size_t size);
-uintmax_t uintmax_from_header (const char * buf, size_t size);
+uintmax_t uintmax_from_header (const char *buf, size_t size);
 
 void list_archive (void);
 void print_for_mkdir (char *dirname, int length, mode_t mode);
@@ -578,6 +589,8 @@ char *quote_copy_string (const char *str);
 int unquote_string (char *str);
 char *zap_slashes (char *name);
 char *normalize_filename (const char *name);
+void replace_prefix (char **pname, const char *samp, size_t slen,
+                    const char *repl, size_t rlen);
 
 void code_ns_fraction (int ns, char *p);
 char const *code_timespec (struct timespec ts, char *sbuf);
index b45c6160b6636555902ba174516e6ade22c86ba5..57732cccaa7fdadf51c872019252002ace7457e7 100644 (file)
@@ -380,7 +380,8 @@ diff_dumpdir (void)
   else
     dev = stat_data.st_dev;
 
-  dumpdir_buffer = scan_directory (current_stat_info.file_name, dev, false);
+  dumpdir_buffer = directory_contents
+                    (scan_directory (current_stat_info.file_name, dev, false));
 
   if (dumpdir_buffer)
     {
index 072732a6195250bd1a9ff436971de709a590bf6f..3a0520c31a77eee127f12169e57281ec48d9afbb 100644 (file)
@@ -1116,11 +1116,12 @@ dump_dir0 (char *directory,
 
       if (!incremental_option)
        finish_header (st, blk, block_ordinal);
-      else if (gnu_list_name->dir_contents)
+      else if (gnu_list_name->directory)
        {
          if (archive_format == POSIX_FORMAT)
            {
-             xheader_store ("GNU.dumpdir", st, gnu_list_name->dir_contents);
+             xheader_store ("GNU.dumpdir", st,
+                            safe_directory_contents (gnu_list_name->directory));
              finish_header (st, blk, block_ordinal);
            }
          else
@@ -1132,11 +1133,8 @@ dump_dir0 (char *directory,
              const char *buffer, *p_buffer;
 
              block_ordinal = current_block_ordinal ();
-             buffer = gnu_list_name->dir_contents;
-             if (buffer)
-               totsize = dumpdir_size (buffer);
-             else
-               totsize = 0;
+             buffer = safe_directory_contents (gnu_list_name->directory);
+             totsize = dumpdir_size (buffer);
              OFF_TO_CHARS (totsize, blk->header.size);
              finish_header (st, blk, block_ordinal);
              p_buffer = buffer;
@@ -1304,7 +1302,7 @@ create_archive (void)
            memcpy (buffer, p, plen);
            if (! ISSLASH (buffer[plen - 1]))
              buffer[plen++] = DIRECTORY_SEPARATOR;
-           q = gnu_list_name->dir_contents;
+           q = directory_contents (gnu_list_name->directory);
            if (q)
              while (*q)
                {
index f5631a142282c7639b8f76affa3e7b6972d11970..aaeda5877ca95fd6af9faa29e6a3dccbdd550cc8 100644 (file)
@@ -290,24 +290,6 @@ attach_directory (const char *name)
 }
                 
 \f
-static void
-replace_prefix (char **pname, const char *samp, size_t slen,
-               const char *repl, size_t rlen)
-{
-  char *name = *pname;
-  size_t nlen = strlen (name);
-  if (nlen > slen && memcmp (name, samp, slen) == 0 && ISSLASH (name[slen]))
-    {
-      if (rlen > slen)
-       {
-         name = xrealloc (name, nlen - slen + rlen + 1);
-         *pname = name;
-       }
-      memmove (name + rlen, name + slen, nlen - slen + 1);
-      memcpy (name, repl, rlen);
-    }
-}
-
 void
 dirlist_replace_prefix (const char *pref, const char *repl)
 {
@@ -389,18 +371,15 @@ remove_directory (const char *caname)
 }
 #endif
 
-/* Find a directory entry for NAME.  If first OLD_PREFIX_LEN
-   bytes of its name match OLD_PREFIX, replace them with
-   NEW_PREFIX. */
+/* If first OLD_PREFIX_LEN bytes of DIR->NAME name match OLD_PREFIX,
+   replace them with NEW_PREFIX. */
 void
-rebase_directory (const char *name, size_t old_prefix_len,
-                 const char *old_prefix,
-                 const char *new_prefix)
+rebase_directory (struct directory *dir,
+                 const char *old_prefix, size_t old_prefix_len,
+                 const char *new_prefix, size_t new_prefix_len)
 {
-  struct directory *dir = find_directory (name);
-  if (dir)
-    replace_prefix (&dir->name, old_prefix, old_prefix_len,
-                   new_prefix, strlen (new_prefix));
+  replace_prefix (&dir->name, old_prefix, old_prefix_len,
+                 new_prefix, new_prefix_len);
 }
 
 /* Return a directory entry for a given combination of device and inode
@@ -696,8 +675,10 @@ makedumpdir (struct directory *directory, const char *dir)
 /* Recursively scan the given directory DIR.
    DEVICE is the device number where DIR resides (for --one-file-system).
    If CMDLINE is true, the directory name was explicitly listed in the
-   command line. */
-const char *
+   command line.
+   Unless *PDIR is NULL, store there a pointer to the struct directory
+   describing DIR. */
+struct directory *
 scan_directory (char *dir, dev_t device, bool cmdline)
 {
   char *dirp = savedir (dir);  /* for scanning directory */
@@ -730,7 +711,7 @@ scan_directory (char *dir, dev_t device, bool cmdline)
   directory = procdir (name_buffer, &stat_data, device,
                       (cmdline ? PD_FORCE_INIT : 0),
                       &ch);
-      
+  
   name_length = strlen (name_buffer); 
   if (! ISSLASH (name_buffer[name_length - 1]))
     {
@@ -808,13 +789,30 @@ scan_directory (char *dir, dev_t device, bool cmdline)
   if (dirp)
     free (dirp);
 
-  return directory->dump ? directory->dump->contents : NULL;
+  return directory;
+}
+
+/* Return pointer to the contents of the directory DIR */
+const char *
+directory_contents (struct directory *dir)
+{
+  if (!dir)
+    return NULL;
+  return dir->dump ? dir->dump->contents : NULL;
 }
 
+/* A "safe" version of directory_contents, which never returns NULL. */
 const char *
-get_directory_contents (char *dir, dev_t device, bool force)
+safe_directory_contents (struct directory *dir)
 {
-  return scan_directory (dir, device, force);
+  const char *ret = directory_contents (dir);
+  return ret ? ret : "\0\0\0\0";
+}
+
+void
+name_fill_directory (struct name *name, dev_t device, bool cmdline)
+{
+  name->directory = scan_directory (name->name, device, cmdline);
 }
 
 \f
@@ -877,17 +875,19 @@ store_rename (struct directory *dir, struct obstack *stk)
     }
 }
 
-const char *
-append_incremental_renames (const char *dump)
+void
+append_incremental_renames (struct directory *dir)
 {
   struct obstack stk;
   size_t size;
   struct directory *dp;
+  const char *dump;
   
   if (dirhead == NULL)
-    return dump;
+    return;
 
   obstack_init (&stk);
+  dump = directory_contents (dir);
   if (dump)
     {
       size = dumpdir_size (dump) - 1;
@@ -902,11 +902,10 @@ append_incremental_renames (const char *dump)
   if (obstack_object_size (&stk) != size)
     {
       obstack_1grow (&stk, 0);
-      dump = obstack_finish (&stk);
+      dumpdir_free (dir->dump);
+      dir->dump = dumpdir_create (obstack_finish (&stk));
     }
-  else
-    obstack_free (&stk, NULL);
-  return dump;
+  obstack_free (&stk, NULL);
 }
 
 \f
index b56a916b1557a87175c5ea57e308a186c3259b67..a76b24eb6764cc85106c8bc38fbfa94f446f76f0 100644 (file)
@@ -236,6 +236,25 @@ normalize_filename (const char *name)
   return zap_slashes (canonicalize_filename_mode (name, CAN_MISSING));
 }
 
+\f
+void
+replace_prefix (char **pname, const char *samp, size_t slen,
+               const char *repl, size_t rlen)
+{
+  char *name = *pname;
+  size_t nlen = strlen (name);
+  if (nlen > slen && memcmp (name, samp, slen) == 0 && ISSLASH (name[slen]))
+    {
+      if (rlen > slen)
+       {
+         name = xrealloc (name, nlen - slen + rlen + 1);
+         *pname = name;
+       }
+      memmove (name + rlen, name + slen, nlen - slen + 1);
+      memcpy (name, repl, rlen);
+    }
+}
+
 \f
 /* Handling numbers.  */
 
@@ -777,3 +796,4 @@ page_aligned_alloc (void **ptr, size_t size)
   *ptr = xmalloc (size1);
   return ptr_align (*ptr, alignment);
 }
+
index 0a282b9c071f516eb6bf58e021877e063bfe6798..78cb5438631c07d25acd8840cef1bd9e5ad7bf9b 100644 (file)
@@ -418,7 +418,7 @@ name_gather (void)
          buffer->next = 0;
          buffer->found_count = 0;
          buffer->matching_flags = matching_flags;
-         buffer->dir_contents = NULL;
+         buffer->directory = NULL;
          buffer->parent = NULL;
          
          namelist = buffer;
@@ -461,7 +461,7 @@ addname (char const *string, int change_dir, struct name *parent)
   name->found_count = 0;
   name->matching_flags = matching_flags;
   name->change_dir = change_dir;
-  name->dir_contents = NULL;
+  name->directory = NULL;
   name->parent = parent;
   
   *nametail = name;
@@ -767,12 +767,11 @@ compare_names (struct name const *n1, struct name const *n2)
 static void
 add_hierarchy_to_namelist (struct name *name, dev_t device, bool cmdline)
 {
-  char *file_name = name->name;
-  const char *buffer = scan_directory (file_name, device, cmdline);
+  const char *buffer;
   
-  if (! buffer)
-    name->dir_contents = "\0\0\0\0";
-  else
+  name_fill_directory (name, device, cmdline);
+  buffer = directory_contents (name->directory);
+  if (buffer)
     {
       struct name *child_head = NULL, *child_tail = NULL;
       size_t name_length = name->length;
@@ -785,8 +784,7 @@ add_hierarchy_to_namelist (struct name *name, dev_t device, bool cmdline)
       size_t string_length;
       int change_dir = name->change_dir;
 
-      name->dir_contents = buffer;
-      strcpy (namebuf, file_name);
+      strcpy (namebuf, name->name);
       if (! ISSLASH (namebuf[name_length - 1]))
        {
          namebuf[name_length++] = '/';
@@ -866,8 +864,9 @@ rebase_child_list (struct name *child, struct name *parent)
       child->name = newp;
       child->length = size;
 
-      rebase_directory (child->name, old_prefix_len, child->parent->name,
-                       new_prefix);
+      rebase_directory (child->directory,
+                       child->parent->name, old_prefix_len, 
+                       new_prefix, new_prefix_len);
     }
 }
 
@@ -915,7 +914,7 @@ collect_and_sort_names (void)
   num_names = 0;
   for (name = namelist; name; name = name->next, num_names++)
     {
-      if (name->found_count || name->dir_contents)
+      if (name->found_count || name->directory)
        continue;
       if (name->matching_flags & EXCLUDE_WILDCARDS)
        /* NOTE: EXCLUDE_ANCHORED is not relevant here */
@@ -990,7 +989,7 @@ collect_and_sort_names (void)
       for (name = namelist; name && name->name[0] == 0; name++)
        ;
       if (name)
-       name->dir_contents = append_incremental_renames (name->dir_contents);
+       append_incremental_renames (name->directory);
     }
 }
 
index 64b173010ef3b539b89ccbdca5838a5f9b7e9c7a..77b213c5e5d9c73cfbe41a2ff55080b740e3a52d 100644 (file)
@@ -76,6 +76,8 @@ TESTSUITE_AT = \
  incr02.at\
  incr03.at\
  incr04.at\
+ incr05.at\
+ incr06.at\
  indexfile.at\
  ignfail.at\
  link01.at\
diff --git a/tests/incr05.at b/tests/incr05.at
new file mode 100644 (file)
index 0000000..7b740d0
--- /dev/null
@@ -0,0 +1,49 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright (C) 2009 Free Software Foundation, Inc.
+
+# 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.
+
+# 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.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([incremental dumps with -C])
+AT_KEYWORDS([incremental incr05])
+
+AT_TAR_CHECK([
+mkdir dir
+mkdir dir/sub
+genfile --file dir/file1
+genfile --file dir/sub/file2
+
+dbfile=`pwd`/db
+
+echo Level 0
+tar -c -f archive.tar -g $dbfile -C dir -v --warning=no-new-dir .
+
+genfile --file dir/file3
+echo Level 1
+tar -c -f archive.tar -g $dbfile -C dir -v --warning=no-new-dir .
+],
+[0],
+[Level 0
+./
+./sub/
+./file1
+./sub/file2
+Level 1
+./
+./sub/
+./file3
+],[],[],[],[gnu, oldgnu, posix])
+
+AT_CLEANUP
diff --git a/tests/incr06.at b/tests/incr06.at
new file mode 100644 (file)
index 0000000..6fcac3a
--- /dev/null
@@ -0,0 +1,81 @@
+# Process this file with autom4te to create testsuite. -*- Autotest -*-
+
+# Test suite for GNU tar.
+# Copyright (C) 2009 Free Software Foundation, Inc.
+
+# 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.
+
+# 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.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([incremental dumps of nested directories])
+AT_KEYWORDS([incremental incr06])
+
+AT_TAR_CHECK([
+mkdir dir
+mkdir dir/sub
+mkdir dir/sub/a
+mkdir dir/sub/b
+genfile --file dir/file1
+genfile --file dir/sub/file2
+genfile --file dir/sub/a/file3
+
+dbfile=`pwd`/db
+
+echo Level 0 . sub
+tar -c -f archive-0.1.tar -g $dbfile.1 -C dir -v --warning=no-new-dir . sub
+echo Level 0 sub .
+tar -c -f archive-0.2.tar -g $dbfile.2 -C dir -v --warning=no-new-dir sub .
+
+mkdir dir/c
+genfile --file dir/sub/b/file4
+
+echo Level 1 . sub
+tar -c -f archive-1.1.tar -g $dbfile.1 -C dir -v --warning=no-new-dir . sub
+echo Level 1 sub .
+tar -c -f archive-1.2.tar -g $dbfile.2 -C dir -v --warning=no-new-dir sub .
+],
+[0],
+[Level 0 . sub
+./
+sub/
+sub/a/
+sub/b/
+./file1
+sub/file2
+sub/a/file3
+Level 0 sub .
+./
+sub/
+sub/a/
+sub/b/
+./file1
+sub/file2
+sub/a/file3
+Level 1 . sub
+./
+./c/
+sub/
+sub/a/
+sub/b/
+sub/b/file4
+Level 1 sub .
+./
+./c/
+sub/
+sub/a/
+sub/b/
+sub/b/file4
+],[],[],[],[gnu, oldgnu, posix])
+
+AT_CLEANUP
+
+
index 2c87281c5e0ed9d34c3d834c5714bdbc4336bcd9..9634c28641dcc512f6420b9d820d43df2bc9c362 100644 (file)
@@ -152,6 +152,8 @@ m4_include([listed01.at])
 m4_include([listed02.at])
 m4_include([incr03.at])
 m4_include([incr04.at])
+m4_include([incr05.at])
+m4_include([incr06.at])
 m4_include([rename01.at])
 m4_include([rename02.at])
 m4_include([rename03.at])
This page took 0.060337 seconds and 4 git commands to generate.