Description: Ensure clamav db is updated only if needed and with proper owner/mode
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 maldetect (1.6.4-1~eebpo120+3.1) bookworm-ee; urgency=medium
 .
   * Ensure clamav db files are updated only if needed
   * Ensure clamav db files are clamav:clamav / 0644
Author: Emmanuel Lacour <elacour@easter-eggs.com>

---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>
Last-Update: 2026-04-21

--- maldetect-1.6.4.orig/files/internals/functions
+++ maldetect-1.6.4/files/internals/functions
@@ -362,9 +362,15 @@ import_conf() {
 clamav_linksigs() {
 	cpath="$1"
 	if [ -d "$cpath" ]; then
-                chmod 644 $sigdir/rfxn.{hdb,ndb,yara} 2> /dev/null
-		rm -f $cpath/rfxn.{hdb,ndb,yara} 2> /dev/null ; cp -f $sigdir/rfxn.{hdb,ndb,yara} $cpath/ 2> /dev/null
-		rm -f $cpath/lmd.user.* 2> /dev/null ; cp -f $sigdir/lmd.user.ndb $sigdir/lmd.user.hdb $cpath/ 2> /dev/null
+		for file in rfxn.hdb rfxn.nbd rfxn.yara lmd.user.ndb lmd.user.hdb
+		do
+			[ -f "$sigdir/$file" ] || continue
+			if ! cmp -s "$sigdir/$file" "$cpath/$file"
+			then
+				eout "updating $cpath/$file" 1
+				install -o clamav -g clamav -m 0644 "$sigdir/$file" "$cpath/"
+			fi
+		done
 	fi
 }
 
