]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
urlfiler: Cleanup list directory during update
authorStefan Schantl <stefan.schantl@ipfire.org>
Sun, 22 Feb 2026 19:07:52 +0000 (20:07 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 23 Feb 2026 10:50:33 +0000 (10:50 +0000)
Cleanup the directory which contains the downloaded blocklists during
the update process. As the same code is used for sheduled and manual
updates/list installs this also cleans up old lists when switching the
lists provider.

Fixes #13820.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
config/urlfilter/autoupdate.pl

index 39b9b4f0b572f9fb0c6e1a68f851e86101d9cc69..05db6e339527dff9ffbbf847dc90662148a935bb 100644 (file)
@@ -7,6 +7,7 @@
 # $Id: autoupdate.pl,v 1.1 2007/03/14 00:00:00 marco.s Exp $
 #
 use strict;
+use File::Path;
 
 require "/var/ipfire/general-functions.pl";
 
@@ -115,6 +116,7 @@ unless ($blacklist_url eq '')
 
                        system("/usr/bin/squidGuard -d -c $target/update.conf -C all");
 
+                       &cleanupdbdir();
                        system("cp -r $target/blacklists/* $dbdir");
 
                        system("chown -R nobody.nobody $dbdir");
@@ -214,3 +216,27 @@ sub setpermissions
 }
 
 # -------------------------------------------------------------------
+
+sub cleanupdbdir {
+       # Open the database directory and do a directory listing.
+       opendir(DIR, "$dbdir") or die "Cannot open $dbdir. $!\n";
+
+       # Loop through the directory.
+       while (my $item = readdir(DIR)) {
+               # Skip . and ..
+               next if ($item eq ".");
+               next if ($item eq "..");
+
+               # Generate absolute path.
+               my $abs_path = "$dbdir/$item";
+
+               # Skip anything which is not a directory.
+               next unless (-d "$abs_path");
+
+               # Remove the directory and the content.
+               &File::Path::remove_tree($abs_path);
+       }
+
+       # Close directory handle.
+       closedir(DIR);
+}