From: Michael Tremer Date: Thu, 23 Jun 2022 13:04:59 +0000 (+0000) Subject: export: Don't fail when output stream isn't seekable X-Git-Tag: 0.9.14~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4c22636cea523fa809eaa4a5f15c85532f806ed;p=location%2Flibloc.git export: Don't fail when output stream isn't seekable For the ipset format, we will rewrite the header after we know the total number of entries that have been written in order to optimise the hash table. When the output stream isn't seekable, we cannot write the header again which is being fixed in this patch. Fixes: #12885 Reported-by: Jon Murphy Signed-off-by: Michael Tremer --- diff --git a/src/python/location/export.py b/src/python/location/export.py index 054e494..f5ed37f 100644 --- a/src/python/location/export.py +++ b/src/python/location/export.py @@ -181,7 +181,12 @@ class IpsetOutputWriter(OutputWriter): def _write_footer(self): # Jump back to the beginning of the file - self.f.seek(0) + try: + self.f.seek(0) + + # If the output stream isn't seekable, we won't try writing the header again + except io.UnsupportedOperation: + return # Rewrite the header with better configuration self._write_header()