Created utility function to extract extension from filename, fixed tests
diff --git a/programs/fileio.c b/programs/fileio.c
index e59fb80..c0d6494 100644
--- a/programs/fileio.c
+++ b/programs/fileio.c
@@ -1430,6 +1430,9 @@
return result;
}
+/* List used to compare file extensions (used with --exclude-compressed flag)
+* Different from the suffixList and should only apply to ZSTD compress operationResult
+*/
static const char *compressedFileExtensions[] = {
ZSTD_EXTENSION,
TZSTD_EXTENSION,
diff --git a/programs/util.c b/programs/util.c
index 7212f7b..f6933bc 100644
--- a/programs/util.c
+++ b/programs/util.c
@@ -326,23 +326,32 @@
#endif /* #ifdef _WIN32 */
-/* Check if the file is precompressed (.zst, .lz4, .gz, .xz).
-YES => Skip the file (return 0)
-NO => return 1
+/* Check if the file is Compressed by comparing it with compressFileExtension list.
+YES => Skip the file (return 1)
+NO => return 0
*/
int UTIL_isCompressedFile(const char *inputName, const char *extensionList[])
{
+ const char* ext = UTIL_getFileExtension(inputName);
while(*extensionList!=NULL)
{
- const char* ext = strstr(inputName,*extensionList);
- if(ext)
+ const char* isCompressedExtension = strstr(ext,*extensionList);
+ if(isCompressedExtension)
return 1;
++extensionList;
}
return 0;
}
+/*Utility function to get file extension from file */
+const char* UTIL_getFileExtension(const char* infilename)
+{
+ const char* extension = strrchr(infilename, '.');
+ if(!extension || extension==infilename) return "";
+ return extension;
+}
+
/*
* UTIL_createFileList - takes a list of files and directories (params: inputNames, inputNamesNb), scans directories,
* and returns a new list of files (params: return value, allocatedBuffer, allocatedNamesNb).
diff --git a/programs/util.h b/programs/util.h
index deaea03..0d0642c 100644
--- a/programs/util.h
+++ b/programs/util.h
@@ -135,6 +135,8 @@
int UTIL_isSameFile(const char* file1, const char* file2);
int UTIL_compareStr(const void *p1, const void *p2);
int UTIL_isCompressedFile(const char* infilename, const char *extensionList[]);
+const char* UTIL_getFileExtension(const char* infilename);
+
U32 UTIL_isFIFO(const char* infilename);
U32 UTIL_isLink(const char* infilename);
#define UTIL_FILESIZE_UNKNOWN ((U64)(-1))