Handle --skip-compress right for new compressors
authorWayne Davison <wayne@opencoder.net>
Wed, 3 Jun 2020 00:58:24 +0000 (17:58 -0700)
committerWayne Davison <wayne@opencoder.net>
Wed, 3 Jun 2020 01:06:09 +0000 (18:06 -0700)
Some compressors can't completely turn off, so minimize the level
when a file is being "skipped".

rsync.yo
rsyncd.conf.yo
token.c

index 3db3f3e84a4a597ebcf4509ef35fadc3bee8b142..dfcda72b3460d00e98f0a2452998d4d0b132be0b 100644 (file)
--- a/rsync.yo
+++ b/rsync.yo
@@ -2116,10 +2116,15 @@ dit(bf(--compress-level=NUM)) Explicitly set the compression level to use
 the bf(--compress) option is implied.
 
 dit(bf(--skip-compress=LIST)) Override the list of file suffixes that will
-not be compressed.  The bf(LIST) should be one or more file suffixes
-(without the dot) separated by slashes (/).
+be compressed as little as possible. Rsync sets the compression level on a
+per-file basis based on the file's suffix.
+If the compression algorithm has an "off" level (such as zlib/zlibx) then no
+compression occurs for those files.  Other algorithms have the level minimized
+to reduces the CPU usage as much as possible.
 
-You may specify an empty string to indicate that no file should be skipped.
+The bf(LIST) should be one or more file suffixes (without the dot) separated by
+slashes (/). You may specify an empty string to indicate that no files should
+be skipped.
 
 Simple character-class matching is supported: each must consist of a list
 of letters inside the square brackets (e.g. no special classes, such as
@@ -2132,8 +2137,7 @@ matches 2 suffixes):
 
 verb(    --skip-compress=gz/jpg/mp[34]/7z/bz2)
 
-The default list of suffixes that will not be compressed is this (in this
-version of rsync):
+The default file suffixes in the skip-compress list in this version of rsync are:
 
 bf(7z)
 bf(ace)
index d57d02778e54a6ab75d8dd4f63c7f82f4ec06caf..aac4a7f2ea437009aaa2fa7dbd89bf7a8974c0c6 100644 (file)
@@ -824,13 +824,17 @@ dit(bf(dont compress)) This parameter allows you to select
 filenames based on wildcard patterns that should not be compressed
 when pulling files from the daemon (no analogous parameter exists to
 govern the pushing of files to a daemon).
-Compression is expensive in terms of CPU usage, so it
+Compression can be expensive in terms of CPU usage, so it
 is usually good to not try to compress files that won't compress well,
 such as already compressed files.
 
 The "dont compress" parameter takes a space-separated list of
 case-insensitive wildcard patterns. Any source filename matching one
-of the patterns will not be compressed during transfer.
+of the patterns will be compressed as little as possible during the
+transfer.
+If the compression algorithm has an "off" level (such as zlib/zlibx) then no
+compression occurs for those files.  Other algorithms have the level minimized
+to reduces the CPU usage as much as possible.
 
 See the bf(--skip-compress) parameter in the bf(rsync)(1) manpage for the list
 of file suffixes that are not compressed by default.  Specifying a value
diff --git a/token.c b/token.c
index bea37f213107ef6d2e29657c1f6def6c78c65c90..f169b756965af7077c3774c86b917968ba92c9bb 100644 (file)
--- a/token.c
+++ b/token.c
@@ -39,7 +39,9 @@ extern char *skip_compress;
 #define Z_INSERT_ONLY Z_SYNC_FLUSH
 #endif
 
-static int compression_level, per_file_default_level;
+static int compression_level; /* The compression level for the current file. */
+static int skip_compression_level; /* The least possible compressing for handling skip-compress files. */
+static int per_file_default_level; /* The default level that each new file gets prior to checking its suffix. */
 
 struct suffix_tree {
        struct suffix_tree *sibling;
@@ -60,13 +62,13 @@ void init_compression_level(void)
                min_level = 1;
                max_level = Z_BEST_COMPRESSION;
                def_level = 6; /* Z_DEFAULT_COMPRESSION is -1, so set it to the real default */
-               off_level = Z_NO_COMPRESSION;
+               off_level = skip_compression_level = Z_NO_COMPRESSION;
                if (do_compression_level == Z_DEFAULT_COMPRESSION)
                        do_compression_level = def_level;
                break;
 #ifdef SUPPORT_ZSTD
        case CPRES_ZSTD:
-               min_level = ZSTD_minCLevel();
+               min_level = skip_compression_level = ZSTD_minCLevel();
                max_level = ZSTD_maxCLevel();
                def_level = 3;
                off_level = CLVL_NOT_SPECIFIED;
@@ -74,7 +76,7 @@ void init_compression_level(void)
 #endif
 #ifdef SUPPORT_LZ4
        case CPRES_LZ4:
-               min_level = 0;
+               min_level = skip_compression_level = 0;
                max_level = 0;
                def_level = 0;
                off_level = CLVL_NOT_SPECIFIED;
@@ -204,7 +206,7 @@ static void init_set_compression(void)
                        /* Optimize a match-string of "*". */
                        *match_list = '\0';
                        suftree = NULL;
-                       per_file_default_level = 0;
+                       per_file_default_level = skip_compression_level;
                        break;
                }
 
@@ -241,7 +243,7 @@ void set_compression(const char *fname)
 
        for (s = match_list; *s; s += strlen(s) + 1) {
                if (iwildmatch(s, fname)) {
-                       compression_level = 0;
+                       compression_level = skip_compression_level;
                        return;
                }
        }
@@ -261,7 +263,7 @@ void set_compression(const char *fname)
                }
                if ((ltr = *++s) == '\0') {
                        if (node->word_end)
-                               compression_level = 0;
+                               compression_level = skip_compression_level;
                        return;
                }
                if (!(node = node->child))