]> git.ipfire.org Git - location/libloc.git/commitdiff
export: Make ipset files easily reloadable
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 11 Feb 2022 17:14:02 +0000 (17:14 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 11 Feb 2022 17:14:58 +0000 (17:14 +0000)
This change allows to "restore" a file multiple times without problems.

If the set already exists, the create command will skip it and we will
flush any existing content to load the new one.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/export.py

index 3b9e1e0262634a0fded1c43a2b7f0dce6ed8fe12..a9774e87c36f78f92ed0009fec05dc7569166854 100644 (file)
@@ -90,7 +90,8 @@ class IpsetOutputWriter(OutputWriter):
        suffix = "ipset"
 
        def _write_header(self):
-               self.f.write("create %s hash:net family inet hashsize 1024 maxelem 65536\n" % self.prefix)
+               self.f.write("create %s hash:net family inet hashsize 1024 maxelem 65536 -exist\n" % self.prefix)
+               self.f.write("flush %s\n" % self.prefix)
 
        def write(self, network):
                self.f.write("add %s %s\n" % (self.prefix, network))