This option makes tar sort the entries of directories that will be
added to an archive according to ORDER (none, name, or order).
Based on proposition by Dick Streefland (https://savannah.gnu.org/patch/?7892).
* src/common.h (savedir_sort_order): New global.
* src/create.c: Pass savedir_sort_order to streamsavedir.
* src/misc.c: Likewise.
* src/tar.c: New option --sort.
* NEWS: Update.
* doc/tar.texi: Document the --sort option.
* doc/tar.1: Likewise.
-GNU tar NEWS - User visible changes. 2014-02-13
+GNU tar NEWS - User visible changes. 2014-02-14
Please send GNU tar bug reports to <bug-tar@gnu.org>
\f
Please send GNU tar bug reports to <bug-tar@gnu.org>
\f
extracted outside of the specified directory, even if the archive is
crafted so as to put them elsewhere.
extracted outside of the specified directory, even if the archive is
crafted so as to put them elsewhere.
+* New option --sort
+
+The --sort=ORDER option instructs tar to sort directory entries
+according to ORDER. It takes effect when creating archives.
+Available ORDERs are: none (the default), name and inode. The
+latter may be absent, if the underlying system does not provide
+the necessary information.
+
+Using --sort=name ensures the member ordering in the created archive
+is uniform and reproducible. Using --sort=inode reduces the number
+of disk seeks made when creating the archive and thus can considerably
+speed up archivation.
+
* Manpages
This release includes official tar(1) and rmt(8) manpages.
* Manpages
This release includes official tar(1) and rmt(8) manpages.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
.\"
.\" You should have received a copy of the GNU General Public License
.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
-.TH TAR 1 "January 28, 2014" "TAR" "GNU TAR Manual"
+.TH TAR 1 "February 14, 2014" "TAR" "GNU TAR Manual"
.SH NAME
tar \- an archiving utility
.SH SYNOPSIS
.SH NAME
tar \- an archiving utility
.SH SYNOPSIS
.TP
\fB\-s\fR, \fB\-\-preserve\-order\fR, \fB\-\-same\-order\fR
Sort names to extract to match archive
.TP
\fB\-s\fR, \fB\-\-preserve\-order\fR, \fB\-\-same\-order\fR
Sort names to extract to match archive
+.TP
+\fB\-\-sort=\fIORDER\fR
+When creating an archive, sort directory entries according to
+\fIORDER\fR, which is one of
+.BR none ,
+.BR name ", or"
+.BR inode .
+
+The default is \fB\-\-sort=none\fR, which stores archive members in
+the same order as returned by the operating system.
+
+Using \fB\-\-sort=name\fR ensures the member ordering in the created archive
+is uniform and reproducible.
+
+Using \fB\-\-sort=inode\fR reduces the number of disk seeks made when
+creating the archive and thus can considerably speed up archivation.
+This sorting order is supported only if the underlying system provides
+the necessary information.
.SS Device selection and switching
.TP
\fB\-f\fR, \fB\-\-file\fR=\fIARCHIVE\fR
.SS Device selection and switching
.TP
\fB\-f\fR, \fB\-\-file\fR=\fIARCHIVE\fR
this option to produce warning messages about existing old files
(@pxref{warnings}).
this option to produce warning messages about existing old files
(@pxref{warnings}).
+@opsummary{sort}
+@item --sort=@var{order}
+Specify the directory sorting order when reading directories.
+@var{Order} may be one of the following:
+
+@table @samp
+@item none
+No directory sorting is performed. This is the default.
+
+@item name
+Sort the directory entries on name. The operating system may deliver
+directory entries in a more or less random order, and sorting them
+makes archive creation reproducible.
+
+@item inode
+Sort the directory entries on inode number. Sorting directories on
+inode number may reduce the amount of disk seek operations when
+creating an archive for some file systems.
+
+@end table
+
@opsummary{sparse}
@item --sparse
@itemx -S
@opsummary{sparse}
@item --sparse
@itemx -S
/* Unquote filenames */
GLOBAL bool unquote_option;
/* Unquote filenames */
GLOBAL bool unquote_option;
+GLOBAL int savedir_sort_order;
+
/* Show file or archive names after transformation.
In particular, when creating archive in verbose mode, list member names
as stored in the archive */
/* Show file or archive names after transformation.
In particular, when creating archive in verbose mode, list member names
as stored in the archive */
while (! (st->dirstream = fdopendir (st->fd)))
if (! open_failure_recover (st))
return 0;
while (! (st->dirstream = fdopendir (st->fd)))
if (! open_failure_recover (st))
return 0;
- return streamsavedir (st->dirstream);
+ return streamsavedir (st->dirstream, savedir_sort_order);
}
/* Dump the directory ST. Return true if successful, false (emitting
}
/* Dump the directory ST. Return true if successful, false (emitting
open_error (name);
}
else if (! ((dir = fdopendir (fd))
open_error (name);
}
else if (! ((dir = fdopendir (fd))
- && (ret = streamsavedir (dir))))
+ && (ret = streamsavedir (dir, savedir_sort_order))))
savedir_error (name);
if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0)
savedir_error (name);
if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0)
#include <xstrtol.h>
#include <stdopen.h>
#include <priv-set.h>
#include <xstrtol.h>
#include <stdopen.h>
#include <priv-set.h>
/* Local declarations. */
/* Local declarations. */
SHOW_SNAPSHOT_FIELD_RANGES_OPTION,
SHOW_TRANSFORMED_NAMES_OPTION,
SKIP_OLD_FILES_OPTION,
SHOW_SNAPSHOT_FIELD_RANGES_OPTION,
SHOW_TRANSFORMED_NAMES_OPTION,
SKIP_OLD_FILES_OPTION,
SPARSE_VERSION_OPTION,
STRIP_COMPONENTS_OPTION,
SUFFIX_OPTION,
SPARSE_VERSION_OPTION,
STRIP_COMPONENTS_OPTION,
SUFFIX_OPTION,
" directories until the end of extraction"), GRID+1 },
{"no-delay-directory-restore", NO_DELAY_DIRECTORY_RESTORE_OPTION, 0, 0,
N_("cancel the effect of --delay-directory-restore option"), GRID+1 },
" directories until the end of extraction"), GRID+1 },
{"no-delay-directory-restore", NO_DELAY_DIRECTORY_RESTORE_OPTION, 0, 0,
N_("cancel the effect of --delay-directory-restore option"), GRID+1 },
+ {"sort", SORT_OPTION, N_("ORDER"), 0,
+#if D_INO_IN_DIRENT
+ N_("directory sorting order: none (default), name or inode"
+#else
+ N_("directory sorting order: none (default) or name"
+#endif
+ ), GRID+1 },
#undef GRID
#define GRID 55
#undef GRID
#define GRID 55
/* Either NL or NUL, as decided by the --null option. */
static char filename_terminator;
/* Either NL or NUL, as decided by the --null option. */
static char filename_terminator;
+static char const *const sort_mode_arg[] = {
+ "none",
+ "name",
+ "inode",
+ NULL
+};
+
+static int sort_mode_flag[] = {
+ SAVEDIR_SORT_NONE,
+ SAVEDIR_SORT_NAME,
+ SAVEDIR_SORT_INODE
+};
+
+ARGMATCH_VERIFY (sort_mode_arg, sort_mode_flag);
+
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
show_transformed_names_option = true;
break;
show_transformed_names_option = true;
break;
+ case SORT_OPTION:
+ savedir_sort_order = XARGMATCH ("--sort", arg,
+ sort_mode_arg, sort_mode_flag);
+ break;
+
case SUFFIX_OPTION:
backup_option = true;
args->backup_suffix_string = arg;
case SUFFIX_OPTION:
backup_option = true;
args->backup_suffix_string = arg;
tar_sparse_major = 1;
tar_sparse_minor = 0;
tar_sparse_major = 1;
tar_sparse_minor = 0;
+ savedir_sort_order = SAVEDIR_SORT_NONE;
+
owner_option = -1; owner_name_option = NULL;
group_option = -1; group_name_option = NULL;
owner_option = -1; owner_name_option = NULL;
group_option = -1; group_name_option = NULL;