public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
* [PATCH 1/2] urlfiler: Cleanup list directory during update
@ 2026-02-22 19:07 Stefan Schantl
  2026-02-22 19:07 ` [PATCH 2/2] urlfilter: Fix syntax when calling chown Stefan Schantl
  2026-02-23 11:34 ` [PATCH 1/2] urlfiler: Cleanup list directory during update Michael Tremer
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Schantl @ 2026-02-22 19:07 UTC (permalink / raw)
  To: development; +Cc: Stefan Schantl

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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-02-23 11:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-22 19:07 [PATCH 1/2] urlfiler: Cleanup list directory during update Stefan Schantl
2026-02-22 19:07 ` [PATCH 2/2] urlfilter: Fix syntax when calling chown Stefan Schantl
2026-02-23 11:34 ` [PATCH 1/2] urlfiler: Cleanup list directory during update Michael Tremer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox