[1/2] urlfiler: Cleanup list directory during update

Message ID 20260222190753.10632-1-stefan.schantl@ipfire.org
State Accepted
Commit 9a9f4dabb7abfa47c2de86664e1f6c67a5cdbb28
Headers
Series [1/2] urlfiler: Cleanup list directory during update |

Commit Message

Stefan Schantl 22 Feb 2026, 7:07 p.m. UTC
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>
---
 config/urlfilter/autoupdate.pl | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
  

Comments

Michael Tremer 23 Feb 2026, 11:34 a.m. UTC | #1
Hello Stefan,

Thank you for these patches.

I added another like so that the custom lists will be kept:

  https://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff;h=0ba18609bde216ef9ad8c485a8852e5080e32e34

All the best,
-Michael

> On 22 Feb 2026, at 19:07, Stefan Schantl <stefan.schantl@ipfire.org> wrote:
> 
> 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>
> ---
> config/urlfilter/autoupdate.pl | 26 ++++++++++++++++++++++++++
> 1 file changed, 26 insertions(+)
> 
> diff --git a/config/urlfilter/autoupdate.pl b/config/urlfilter/autoupdate.pl
> index 39b9b4f0b..05db6e339 100644
> --- a/config/urlfilter/autoupdate.pl
> +++ b/config/urlfilter/autoupdate.pl
> @@ -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);
> +}
> -- 
> 2.47.3
> 
>
  

Patch

diff --git a/config/urlfilter/autoupdate.pl b/config/urlfilter/autoupdate.pl
index 39b9b4f0b..05db6e339 100644
--- a/config/urlfilter/autoupdate.pl
+++ b/config/urlfilter/autoupdate.pl
@@ -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);
+}