git: 1f357cdb9252 - main - Tools/scripts: update port_conflicts_check.lua

From: Stefan Eßer <se_at_FreeBSD.org>
Date: Sun, 22 May 2022 20:14:43 UTC
The branch main has been updated by se:

URL: https://cgit.FreeBSD.org/ports/commit/?id=1f357cdb9252a62151de9903f52397374ad1d322

commit 1f357cdb9252a62151de9903f52397374ad1d322
Author:     Stefan Eßer <se@FreeBSD.org>
AuthorDate: 2022-05-22 20:13:41 +0000
Commit:     Stefan Eßer <se@FreeBSD.org>
CommitDate: 2022-05-22 20:13:41 +0000

    Tools/scripts: update port_conflicts_check.lua
    
    Check that the package file database exists and that it is up-to-date.
---
 Tools/scripts/port_conflicts_check.lua | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/Tools/scripts/port_conflicts_check.lua b/Tools/scripts/port_conflicts_check.lua
index ed81ad008298..c5265af19a5a 100755
--- a/Tools/scripts/port_conflicts_check.lua
+++ b/Tools/scripts/port_conflicts_check.lua
@@ -55,6 +55,7 @@ require "lfs"
 -------------------------------------------------------------------
 local file_pattern = "."
 local database = "/var/db/pkg/provides/provides.db"
+local max_age = 1 * 24 * 3600 -- maximum age of database file in seconds
 
 -------------------------------------------------------------------
 local function table_sorted_keys(t)
@@ -154,6 +155,20 @@ end
 -------------------------------------------------------------------
 local function read_files(pattern)
    local files_table = {}
+   local now = os.time()
+   local modification_time = lfs.attributes(database, "modification")
+   if not modification_time then
+      print("# Aborting: package file database " .. database .. " does not exist.")
+      print("# Install the 'pkg-provides' package and add it as a module to 'pkg.conf'.")
+      print("# Then fetch the database with 'pkg update' or 'pkg provides -u'.")
+      os.exit(1)
+   end
+   if now - modification_time > max_age then
+      print("# Aborting: package file database " .. database)
+      print("# is older than " .. max_age .. " seconds.")
+      print("# Use 'pkg provides -u' to update the database.")
+      os.exit(2)
+   end
    local pipe = io.popen("locate -d " .. database .. " " .. pattern)
    if pipe then
       for line in pipe:lines() do