]> granicus.if.org Git - xz/commitdiff
xz: Check if the file already has custom suffix when compressing.
authorLasse Collin <lasse.collin@tukaani.org>
Fri, 4 Feb 2011 09:29:47 +0000 (11:29 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Fri, 4 Feb 2011 09:29:47 +0000 (11:29 +0200)
Now "xz -S .test foo.test" refuses to compress the
file because it already has the suffix .test. The man
page had it documented this way already.

src/xz/suffix.c

index ea86c1a3f6b931bc73e26c65c2f5e3a3420e897e..f795e2ad322e0034aa77aab8db71e6f377f2a28a 100644 (file)
@@ -183,6 +183,15 @@ compressed_name(const char *src_name, const size_t src_len)
                }
        }
 
+       if (custom_suffix != NULL) {
+               if (test_suffix(custom_suffix, src_name, src_len) != 0) {
+                       message_warning(_("%s: File already has `%s' "
+                                       "suffix, skipping"), src_name,
+                                       custom_suffix);
+                       return NULL;
+               }
+       }
+
        // TODO: Hmm, maybe it would be better to validate this in args.c,
        // since the suffix handling when decoding is weird now.
        if (opt_format == FORMAT_RAW && custom_suffix == NULL) {