From d2cd64c11da4cb5ba55a5d8cb3bd4ac6d3ba8736 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= <petr.dlouhy@email.cz>
Date: Wed, 2 Feb 2022 11:15:29 +0100
Subject: [PATCH] don't compress files if they already exists

---
 src/whitenoise/compress.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/whitenoise/compress.py b/src/whitenoise/compress.py
index 143e1e44..c2188af9 100644
--- a/src/whitenoise/compress.py
+++ b/src/whitenoise/compress.py
@@ -82,14 +82,14 @@ def compress(self, path):
             stat_result = os.fstat(f.fileno())
             data = f.read()
         size = len(data)
-        if self.use_brotli:
+        if self.use_brotli and not os.path.isfile(f"{path}.br"):
             compressed = self.compress_brotli(data)
             if self.is_compressed_effectively("Brotli", path, size, compressed):
                 yield self.write_data(path, compressed, ".br", stat_result)
             else:
                 # If Brotli compression wasn't effective gzip won't be either
                 return
-        if self.use_gzip:
+        if self.use_gzip and not os.path.isfile(f"{path}.gz"):
             compressed = self.compress_gzip(data)
             if self.is_compressed_effectively("Gzip", path, size, compressed):
                 yield self.write_data(path, compressed, ".gz", stat_result)