]> git.ipfire.org Git - dbl.git/commitdiff
sources: Gracefully skip if a source has given us an empty file
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Feb 2026 17:03:49 +0000 (17:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 16 Feb 2026 17:03:49 +0000 (17:03 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/dbl/sources.py

index bd4ae37162e675e2b14bf740529750bd87dafac0..f2c987070ffadcc2924e77e3afed5a5825707a63 100644 (file)
@@ -220,8 +220,13 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
                                                # Consume, transparently decompress and decode the payload
                                                f = self._consume_payload(response)
 
+                                               # Count parsed lines
+                                               lineno = 0
+
                                                # Add all domains
                                                for line in f:
+                                                       lineno += 1
+
                                                        # Strip any comments
                                                        line, hashtag, comment = line.partition("#")
 
@@ -302,11 +307,20 @@ class Source(sqlmodel.SQLModel, database.BackendMixin, table=True):
                                                        # Add the domain
                                                        domains.add(domain)
 
+                                               # If we downloaded no data, we skip any further processing
+                                               if lineno == 0:
+                                                       log.warning("Downloaded an empty file from %s (%s). Skipping..." \
+                                                               % (self, self.url))
+
+                                                       return False
+
                                                # Log an error if we could not detect the format
                                                if format is None:
                                                        log.error("Format of '%s' (%s) seems to be unkown. No data could be parsed" \
                                                                % (self, self.url))
 
+                                                       return False
+
                                                # Add all domains to the database
                                                self.add_domains(domains)