Skip to content

Commit f229daa

Browse files
authored
Merge pull request #3052 from dirkmueller/gzip_keep
Keep original file if -c or --stdout is given
2 parents 64efba4 + 3f4f8b0 commit f229daa

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

programs/zstd.1

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.
2-
.TH "ZSTD" "1" "January 2022" "zstd 1.5.2" "User Commands"
2+
.TH "ZSTD" "1" "February 2022" "zstd 1.5.2" "User Commands"
33
.
44
.SH "NAME"
55
\fBzstd\fR \- zstd, zstdmt, unzstd, zstdcat \- Compress or decompress \.zst files
@@ -165,7 +165,7 @@ Additionally, this can be used to limit memory for dictionary training\. This pa
165165
\fB\-f\fR, \fB\-\-force\fR: disable input and output checks\. Allows overwriting existing files, input from console, output to stdout, operating on links, block devices, etc\.
166166
.
167167
.IP "\(bu" 4
168-
\fB\-c\fR, \fB\-\-stdout\fR: write to standard output (even if it is the console)
168+
\fB\-c\fR, \fB\-\-stdout\fR: write to standard output (even if it is the console); keep original files unchanged\.
169169
.
170170
.IP "\(bu" 4
171171
\fB\-\-[no\-]sparse\fR: enable / disable sparse FS support, to make files with many zeroes smaller on disk\. Creating sparse files may save disk space and speed up decompression by reducing the amount of disk I/O\. default: enabled when output is into a file, and disabled when output is stdout\. This setting overrides default and can force sparse mode over stdout\.

programs/zstd.1.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ the last one takes effect.
212212
disable input and output checks. Allows overwriting existing files, input
213213
from console, output to stdout, operating on links, block devices, etc.
214214
* `-c`, `--stdout`:
215-
write to standard output (even if it is the console)
215+
write to standard output (even if it is the console); keep original files unchanged.
216216
* `--[no-]sparse`:
217217
enable / disable sparse FS support,
218218
to make files with many zeroes smaller on disk.

programs/zstdcli.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void usage_advanced(const char* programName)
178178
DISPLAYOUT( "Advanced arguments : \n");
179179
DISPLAYOUT( " -V : display Version number and exit \n");
180180

181-
DISPLAYOUT( " -c : write to standard output (even if it is the console) \n");
181+
DISPLAYOUT( " -c : write to standard output (even if it is the console), keep original file \n");
182182

183183
DISPLAYOUT( " -v : verbose mode; specify multiple times to increase verbosity \n");
184184
DISPLAYOUT( " -q : suppress warnings; specify twice to suppress errors too \n");
@@ -925,7 +925,7 @@ int main(int argCount, const char* argv[])
925925
if (!strcmp(argument, "--help")) { usage_advanced(programName); CLEAN_RETURN(0); }
926926
if (!strcmp(argument, "--verbose")) { g_displayLevel++; continue; }
927927
if (!strcmp(argument, "--quiet")) { g_displayLevel--; continue; }
928-
if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; g_displayLevel-=(g_displayLevel==2); continue; }
928+
if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; FIO_setRemoveSrcFile(prefs, 0); g_displayLevel-=(g_displayLevel==2); continue; }
929929
if (!strcmp(argument, "--ultra")) { ultra=1; continue; }
930930
if (!strcmp(argument, "--check")) { FIO_setChecksumFlag(prefs, 2); continue; }
931931
if (!strcmp(argument, "--no-check")) { FIO_setChecksumFlag(prefs, 0); continue; }
@@ -1114,7 +1114,7 @@ int main(int argCount, const char* argv[])
11141114
operation=zom_decompress; argument++; break;
11151115

11161116
/* Force stdout, even if stdout==console */
1117-
case 'c': forceStdout=1; outFileName=stdoutmark; argument++; break;
1117+
case 'c': forceStdout=1; outFileName=stdoutmark; FIO_setRemoveSrcFile(prefs, 0); argument++; break;
11181118

11191119
/* do not store filename - gzip compatibility - nothing to do */
11201120
case 'n': argument++; break;
@@ -1279,7 +1279,7 @@ int main(int argCount, const char* argv[])
12791279
}
12801280

12811281
nbInputFileNames = filenames->tableSize; /* saving number of input files */
1282-
1282+
12831283
if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */
12841284
UTIL_expandFNT(&filenames, followLinks);
12851285
}
@@ -1392,7 +1392,7 @@ int main(int argCount, const char* argv[])
13921392
}
13931393
UTIL_refFilename(filenames, stdinmark);
13941394
}
1395-
1395+
13961396
if (!strcmp(filenames->fileNames[0], stdinmark) && !outFileName)
13971397
outFileName = stdoutmark; /* when input is stdin, default output is stdout */
13981398

tests/cli-tests/compression/basic.sh

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ zstd -c file | zstd -t
2424
zstd --stdout file | zstd -t
2525
println bob | zstd | zstd -t
2626

27+
# Test keeping input file when compressing to stdout in gzip mode
28+
$ZSTD_SYMLINK_DIR/gzip -c file | zstd -t ; test -f file
29+
$ZSTD_SYMLINK_DIR/gzip --stdout file | zstd -t ; test -f file
30+
2731
# Test --rm
2832
cp file file-rm
2933
zstd --rm file-rm; zstd -t file-rm.zst

0 commit comments

Comments
 (0)