stdin multiple file fixes (#3222)
* Fixes for https://github.com/facebook/zstd/issues/3206 - bugs when handling stdin as part of multiple files. * new line at end of multiple-files.sh
This commit is contained in:
parent
d4a5bc4efc
commit
ae4670466c
@ -1796,6 +1796,11 @@ FIO_determineCompressedName(const char* srcFileName, const char* outDirName, con
|
|||||||
char* outDirFilename = NULL;
|
char* outDirFilename = NULL;
|
||||||
size_t sfnSize = strlen(srcFileName);
|
size_t sfnSize = strlen(srcFileName);
|
||||||
size_t const srcSuffixLen = strlen(suffix);
|
size_t const srcSuffixLen = strlen(suffix);
|
||||||
|
|
||||||
|
if(!strcmp(srcFileName, stdinmark)) {
|
||||||
|
return stdoutmark;
|
||||||
|
}
|
||||||
|
|
||||||
if (outDirName) {
|
if (outDirName) {
|
||||||
outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, srcSuffixLen);
|
outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, srcSuffixLen);
|
||||||
sfnSize = strlen(outDirFilename);
|
sfnSize = strlen(outDirFilename);
|
||||||
@ -2579,6 +2584,11 @@ FIO_determineDstName(const char* srcFileName, const char* outDirName)
|
|||||||
|
|
||||||
size_t srcSuffixLen;
|
size_t srcSuffixLen;
|
||||||
const char* const srcSuffix = strrchr(srcFileName, '.');
|
const char* const srcSuffix = strrchr(srcFileName, '.');
|
||||||
|
|
||||||
|
if(!strcmp(srcFileName, stdinmark)) {
|
||||||
|
return stdoutmark;
|
||||||
|
}
|
||||||
|
|
||||||
if (srcSuffix == NULL) {
|
if (srcSuffix == NULL) {
|
||||||
DISPLAYLEVEL(1,
|
DISPLAYLEVEL(1,
|
||||||
"zstd: %s: unknown suffix (%s expected). "
|
"zstd: %s: unknown suffix (%s expected). "
|
||||||
|
@ -509,6 +509,16 @@ FileNamesTable* UTIL_allocateFileNamesTable(size_t tableSize)
|
|||||||
return fnt;
|
return fnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int UTIL_searchFileNamesTable(FileNamesTable* table, char const* name) {
|
||||||
|
size_t i;
|
||||||
|
for(i=0 ;i < table->tableSize; i++) {
|
||||||
|
if(!strcmp(table->fileNames[i], name)) {
|
||||||
|
return (int)i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
void UTIL_refFilename(FileNamesTable* fnt, const char* filename)
|
void UTIL_refFilename(FileNamesTable* fnt, const char* filename)
|
||||||
{
|
{
|
||||||
assert(fnt->tableSize < fnt->tableCapacity);
|
assert(fnt->tableSize < fnt->tableCapacity);
|
||||||
|
@ -269,6 +269,11 @@ UTIL_createFNT_fromROTable(const char** filenames, size_t nbFilenames);
|
|||||||
*/
|
*/
|
||||||
FileNamesTable* UTIL_allocateFileNamesTable(size_t tableSize);
|
FileNamesTable* UTIL_allocateFileNamesTable(size_t tableSize);
|
||||||
|
|
||||||
|
/*! UTIL_searchFileNamesTable() :
|
||||||
|
* Searched through entries in FileNamesTable for a specific name.
|
||||||
|
* @return : index of entry if found or -1 if not found
|
||||||
|
*/
|
||||||
|
int UTIL_searchFileNamesTable(FileNamesTable* table, char const* name);
|
||||||
|
|
||||||
/*! UTIL_refFilename() :
|
/*! UTIL_refFilename() :
|
||||||
* Add a reference to read-only name into @fnt table.
|
* Add a reference to read-only name into @fnt table.
|
||||||
|
@ -1391,19 +1391,19 @@ int main(int argCount, const char* argv[])
|
|||||||
UTIL_refFilename(filenames, stdinmark);
|
UTIL_refFilename(filenames, stdinmark);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(filenames->fileNames[0], stdinmark) && !outFileName)
|
if (filenames->tableSize == 1 && !strcmp(filenames->fileNames[0], stdinmark) && !outFileName)
|
||||||
outFileName = stdoutmark; /* when input is stdin, default output is stdout */
|
outFileName = stdoutmark; /* when input is stdin, default output is stdout */
|
||||||
|
|
||||||
/* Check if input/output defined as console; trigger an error in this case */
|
/* Check if input/output defined as console; trigger an error in this case */
|
||||||
if (!forceStdin
|
if (!forceStdin
|
||||||
&& !strcmp(filenames->fileNames[0], stdinmark)
|
&& (UTIL_searchFileNamesTable(filenames, stdinmark) != -1)
|
||||||
&& IS_CONSOLE(stdin) ) {
|
&& IS_CONSOLE(stdin) ) {
|
||||||
DISPLAYLEVEL(1, "stdin is a console, aborting\n");
|
DISPLAYLEVEL(1, "stdin is a console, aborting\n");
|
||||||
CLEAN_RETURN(1);
|
CLEAN_RETURN(1);
|
||||||
}
|
}
|
||||||
if ( outFileName && !strcmp(outFileName, stdoutmark)
|
if ( (!outFileName || !strcmp(outFileName, stdoutmark))
|
||||||
&& IS_CONSOLE(stdout)
|
&& IS_CONSOLE(stdout)
|
||||||
&& !strcmp(filenames->fileNames[0], stdinmark)
|
&& (UTIL_searchFileNamesTable(filenames, stdinmark) != -1)
|
||||||
&& !forceStdout
|
&& !forceStdout
|
||||||
&& operation!=zom_decompress ) {
|
&& operation!=zom_decompress ) {
|
||||||
DISPLAYLEVEL(1, "stdout is a console, aborting\n");
|
DISPLAYLEVEL(1, "stdout is a console, aborting\n");
|
||||||
|
21
tests/cli-tests/compression/multiple-files.sh
Executable file
21
tests/cli-tests/compression/multiple-files.sh
Executable file
@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# setup
|
||||||
|
echo "file1" > file1
|
||||||
|
echo "file2" > file2
|
||||||
|
|
||||||
|
echo "Test zstd ./file1 - file2"
|
||||||
|
rm -f ./file*.zst
|
||||||
|
echo "stdin" | zstd ./file1 - ./file2 | zstd -d
|
||||||
|
cat file1.zst | zstd -d
|
||||||
|
cat file2.zst | zstd -d
|
||||||
|
|
||||||
|
echo "Test zstd -d ./file1.zst - file2.zst"
|
||||||
|
rm ./file1 ./file2
|
||||||
|
echo "stdin" | zstd - | zstd -d ./file1.zst - file2.zst
|
||||||
|
cat file1
|
||||||
|
cat file2
|
||||||
|
|
||||||
|
echo "zstd -d ./file1.zst - file2.zst -c"
|
||||||
|
echo "stdin" | zstd | zstd -d ./file1.zst - file2.zst -c
|
12
tests/cli-tests/compression/multiple-files.sh.stdout.exact
Normal file
12
tests/cli-tests/compression/multiple-files.sh.stdout.exact
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
Test zstd ./file1 - file2
|
||||||
|
stdin
|
||||||
|
file1
|
||||||
|
file2
|
||||||
|
Test zstd -d ./file1.zst - file2.zst
|
||||||
|
stdin
|
||||||
|
file1
|
||||||
|
file2
|
||||||
|
zstd -d ./file1.zst - file2.zst -c
|
||||||
|
file1
|
||||||
|
stdin
|
||||||
|
file2
|
Loading…
x
Reference in New Issue
Block a user