]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Merge branch 'tzst-ext-tmp' into tzst-ext 1790/head
authorFelix Handte <w@felixhandte.com>
Thu, 24 Oct 2019 21:49:34 +0000 (17:49 -0400)
committerGitHub <noreply@github.com>
Thu, 24 Oct 2019 21:49:34 +0000 (17:49 -0400)
1  2 
programs/fileio.c
programs/fileio.h

index 5aaad0e96cc8f853dae9ef67e4a3973d461062ca,0365f144991fdfbbfa1955891c4ea9d20c3fb35a..07503f0526ccd310252033a7447a7fafbc10e936
@@@ -2168,39 -2297,55 +2297,46 @@@ FIO_determineDstName(const char* srcFil
  {
      static size_t dfnbCapacity = 0;
      static char* dstFileNameBuffer = NULL;   /* using static allocation : this function cannot be multi-threaded */
-     size_t const sfnSize = strlen(srcFileName);
+     char* outDirFilename = NULL;
 +
 +    const char* SUFFIX_LIST = ZSTD_EXTENSION "/" TZSTD_EXTENSION
 +    #ifdef ZSTD_GZDECOMPRESS
 +        "/" GZ_EXTENSION "/" TGZ_EXTENSION
 +    #endif
 +    #ifdef ZSTD_LZMADECOMPRESS
 +        "/" XZ_EXTENSION "/" LZMA_EXTENSION "/" TXZ_EXTENSION
 +    #endif
 +    #ifdef ZSTD_LZ4DECOMPRESS
 +        "/" LZ4_EXTENSION "/" TLZ4_EXTENSION
 +    #endif
 +    ;
 +
+     size_t sfnSize = strlen(srcFileName);
      size_t suffixSize;
      const char* const suffixPtr = strrchr(srcFileName, '.');
      if (suffixPtr == NULL) {
 -        DISPLAYLEVEL(1, "zstd: %s: unknown suffix -- ignored \n",
 -                        srcFileName);
 +        DISPLAYLEVEL(1, "zstd: %s: missing suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n",
 +                        srcFileName, SUFFIX_LIST);
          return NULL;
      }
      suffixSize = strlen(suffixPtr);
  
      /* check suffix is authorized */
      if (sfnSize <= suffixSize
 -        || (   strcmp(suffixPtr, ZSTD_EXTENSION)
 -        #ifdef ZSTD_GZDECOMPRESS
 -            && strcmp(suffixPtr, GZ_EXTENSION)
 -        #endif
 -        #ifdef ZSTD_LZMADECOMPRESS
 -            && strcmp(suffixPtr, XZ_EXTENSION)
 -            && strcmp(suffixPtr, LZMA_EXTENSION)
 -        #endif
 -        #ifdef ZSTD_LZ4DECOMPRESS
 -            && strcmp(suffixPtr, LZ4_EXTENSION)
 -        #endif
 -            ) ) {
 -        const char* suffixlist = ZSTD_EXTENSION
 -        #ifdef ZSTD_GZDECOMPRESS
 -            "/" GZ_EXTENSION
 -        #endif
 -        #ifdef ZSTD_LZMADECOMPRESS
 -            "/" XZ_EXTENSION "/" LZMA_EXTENSION
 -        #endif
 -        #ifdef ZSTD_LZ4DECOMPRESS
 -            "/" LZ4_EXTENSION
 -        #endif
 -        ;
 -        DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected) -- ignored \n",
 -                     srcFileName, suffixlist);
 +        || (strstr(SUFFIX_LIST, suffixPtr) == NULL)) {
 +        DISPLAYLEVEL(1, "zstd: %s: unknown suffix (%s expected). Can't derive the output file name so specify it with -o dstFileName. -- ignored \n",
 +                     srcFileName, SUFFIX_LIST);
          return NULL;
      }
+     if (outDirName) {
+         outDirFilename = FIO_createFilename_fromOutDir(srcFileName, outDirName, 0);
+         sfnSize = strlen(outDirFilename);
+         assert(outDirFilename != NULL);
+     }
  
-     /* allocate enough space to write dstFilename into it */
      if (dfnbCapacity+suffixSize <= sfnSize+1) {
+         /* allocate enough space to write dstFilename into it */
          free(dstFileNameBuffer);
          dfnbCapacity = sfnSize + 20;
          dstFileNameBuffer = (char*)malloc(dfnbCapacity);
  
      /* return dst name == src name truncated from suffix */
      assert(dstFileNameBuffer != NULL);
-     memcpy(dstFileNameBuffer, srcFileName, dstFileNameEndPos);
 +    size_t dstFileNameEndPos = sfnSize - suffixSize;
 -        memcpy(dstFileNameBuffer, outDirFilename, sfnSize - suffixSize);
+     if (outDirFilename) {
 -        memcpy(dstFileNameBuffer, srcFileName, sfnSize - suffixSize);
 -    }
 -    dstFileNameBuffer[sfnSize-suffixSize] = '\0';
++        memcpy(dstFileNameBuffer, outDirFilename, dstFileNameEndPos);
+         free(outDirFilename);
+     } else {
++        memcpy(dstFileNameBuffer, srcFileName, dstFileNameEndPos);
++    }
 +    /* The short tar extensions tzst, tgz, txz and tlz4 files should have "tar" extension on decompression
 +     * To check that the file is one of them we can check that it starts with "t"
 +     */
 +    if (suffixPtr[1] == 't') {
 +        dstFileNameBuffer[dstFileNameEndPos++] = '.';
 +        dstFileNameBuffer[dstFileNameEndPos++] = 't';
 +        dstFileNameBuffer[dstFileNameEndPos++] = 'a';
 +        dstFileNameBuffer[dstFileNameEndPos++] = 'r';
 +    }
 +    dstFileNameBuffer[dstFileNameEndPos] = '\0';
      return dstFileNameBuffer;
  
      /* note : dstFileNameBuffer memory is not going to be free */
Simple merge