** Changes in behavior
- When acting in-place, gzip now fsyncs the output before closing it.
- This is slower, but on many file systems it is safer if the system
- is about to crash.
-
The GZIP environment variable is now obsolescent; gzip now warns if
it is used, and rejects attempts to use dangerous options or operands.
You can use an alias or script instead.
+** New features
+
+ gzip now accepts the --synchronous option, which causes it to use
+ fsync and similar primitives to transfer output data to the output
+ file's storage device when the file system supports this. Although
+ this option makes gzip safer in the presence of system crashes, it
+ can make gzip considerably slower.
+
** Bug fixes
gzip -k -v no longer reports that files are replaced.
-q, --quiet suppress all warnings
-r, --recursive operate recursively on directories
-S, --suffix=SUF use suffix SUF on compressed files
+ --synchronous synchronous output (safer if system crashes, but slower)
-t, --test test compressed file integrity
-v, --verbose verbose mode
-V, --version display version number
Previous versions of gzip used the @samp{.z} suffix. This was changed to
avoid a conflict with @command{pack}.
+@item --synchronous
+Use synchronous output, by transferring output data to the output
+file's storage device when the file system supports this. Because
+file system data can be cached, without this option if the system
+crashes around the time a command like @samp{gzip FOO} is run the user
+might lose both @file{FOO} and @file{FOO.gz}; this is the default with
+@command{gzip}, just as it is the default with most applications that
+move data. When this option is used, @command{gzip} is safer but can
+be considerably slower.
+
@item --test
@itemx -t
Test. Check the compressed file integrity.
is deliberately not documented, and only for testing. */
static bool presume_input_tty;
+/* If true, transfer output data to the output file's storage device
+ when supported. Otherwise, if the system crashes around the time
+ gzip is run, the user might lose both input and output data. See:
+ Pillai TS et al. All file systems are not created equal: on the
+ complexity of crafting crash-consistent applications. OSDI'14. 2014:433-48.
+ https://www.usenix.org/conference/osdi14/technical-sessions/presentation/pillai */
+static bool synchronous;
+
static int ascii = 0; /* convert end-of-lines to local OS conventions */
int to_stdout = 0; /* output to stdout (-c) */
static int decompress = 0; /* decompress (-d) */
enum
{
PRESUME_INPUT_TTY_OPTION = CHAR_MAX + 1,
+ SYNCHRONOUS_OPTION,
/* A value greater than all valid long options, used as a flag to
distinguish options derived from the GZIP environment variable. */
{"-presume-input-tty", no_argument, NULL, PRESUME_INPUT_TTY_OPTION},
{"quiet", 0, 0, 'q'}, /* quiet mode */
{"silent", 0, 0, 'q'}, /* quiet mode */
+ {"synchronous",0, 0, SYNCHRONOUS_OPTION},
{"recursive", 0, 0, 'r'}, /* recurse through directories */
{"suffix", 1, 0, 'S'}, /* use given suffix instead of .gz */
{"test", 0, 0, 't'}, /* test compressed file integrity */
" -r, --recursive operate recursively on directories",
#endif
" -S, --suffix=SUF use suffix SUF on compressed files",
+ " --synchronous synchronous output (safer if system crashes, but slower)",
" -t, --test test compressed file integrity",
" -v, --verbose verbose mode",
" -V, --version display version number",
z_len = strlen(optarg);
z_suffix = optarg;
break;
+ case SYNCHRONOUS_OPTION:
+ synchronous = true;
+ break;
case 't':
test = decompress = to_stdout = 1;
break;
if (list && !quiet && file_count > 1) {
do_list(-1, -1); /* print totals */
}
+ if (to_stdout
+ && ((synchronous
+ && (fdatasync (STDOUT_FILENO) != 0 && errno != EINVAL))
+ || close (STDOUT_FILENO) != 0)
+ && errno != EBADF)
+ write_error ();
do_exit(exit_code);
return exit_code; /* just to avoid lint warning */
}
{
copy_stat (&istat);
- /* If KEEP, transfer output data to the output file's storage device.
- Otherwise, if the system crashed now the user might lose
- both input and output data. See: Pillai TS et al. All
- file systems are not created equal: on the complexity of
- crafting crash-consistent applications. OSDI'14. 2014:433-48.
- https://www.usenix.org/conference/osdi14/technical-sessions/presentation/pillai */
- if ((!keep
+ if ((synchronous
&& ((0 <= dfd && fdatasync (dfd) != 0 && errno != EINVAL)
|| (fsync (ofd) != 0 && errno != EINVAL)))
|| close (ofd) != 0)