New option --sort=ORDER

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.
This commit is contained in:
Sergey Poznyakoff
2014-02-14 00:26:49 +02:00
parent 62497f0e26
commit 29a6964af3
7 changed files with 89 additions and 4 deletions
+19 -1
View File
@@ -13,7 +13,7 @@
.\"
.\" 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
@@ -506,6 +506,24 @@ Try extracting files with the same ownership as exists in the 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
+21
View File
@@ -3319,6 +3319,27 @@ The @option{--warning=existing-file} option can be used together with
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