From 8d6485141369183d9a8622b479b27216e51cde52 Mon Sep 17 00:00:00 2001 From: Robert McLay Date: Thu, 9 Sep 2021 11:56:39 -0500 Subject: [PATCH] Support for spiderPathFilter hook added --- README.new | 2 ++ docs/source/170_hooks.rst | 7 +++++++ src/Hook.lua | 2 ++ src/StandardPackage.lua | 24 ++++++++++++++++++++++ src/spider.in.lua | 42 ++++++++++++++++++--------------------- 5 files changed, 54 insertions(+), 23 deletions(-) diff --git a/README.new b/README.new index c973f309c..dbe8710da 100644 --- a/README.new +++ b/README.new @@ -24,3 +24,5 @@ Lmod 8.5+ * Change MasterControl:myShellType() to use Shell:type() and change shells to report have local variable myType. * Issue #528: Added support for the RC shell. + (8.5.14) * Added spiderPathFilter hook so that sites can control what paths are kept or ignored. + diff --git a/docs/source/170_hooks.rst b/docs/source/170_hooks.rst index d6d6c7f7f..1f6ce6b36 100644 --- a/docs/source/170_hooks.rst +++ b/docs/source/170_hooks.rst @@ -139,6 +139,13 @@ Hook functions property table. See *rt/uitSitePkg/mf/site_scripts/SitePackage.lua* for a complete example. +**spiderPathFilter** (keepA, ignoreA): + This hook returns two arrays: *keepA* and *ignoreA*. The *keepA* is + an array of paths patterns that a site wishes to be stored in the spider + cache. The *ignoreA* is an array of path patterns to ignore in the + cache. See *src/StandardPackage.lua* has an example on how to + implement this hook. + Example Hook: msgHook --------------------- diff --git a/src/Hook.lua b/src/Hook.lua index 0e20fcf97..64ee933e3 100644 --- a/src/Hook.lua +++ b/src/Hook.lua @@ -71,6 +71,8 @@ local validT = isVisibleHook = false, -- Called to evalate if a module should be hidden or not spider_decoration = false, -- This hook adds decoration to spider level one output. -- It can be the category or a property. + spiderPathFilter = false, -- This hook returns two arrays keepA, ignoreA to keep or + -- ignore a path in the spider cache } -------------------------------------------------------------------------- diff --git a/src/StandardPackage.lua b/src/StandardPackage.lua index 97e497e32..3d74f8c54 100644 --- a/src/StandardPackage.lua +++ b/src/StandardPackage.lua @@ -109,4 +109,28 @@ end hook.register("groupName",groupName) +local ignoreA = { + "^$", + "^%.$", + "^%$", + "^%%", + "^/bin/", + "^/bin$", + "^/sbin$", + "^/usr/bin$", + "^/usr/sbin$", + "^/usr/local/share/bin$", + "^/usr/lib/?", + "^/opt/local/bin$", +} + +local keepA = {} + +local function spiderPathFilterHook(keepA, ignoreA) + return +end + +hook.register("spiderPathFilter",spiderPathFilterHook) + + sandbox_registration { Pkg = Pkg } diff --git a/src/spider.in.lua b/src/spider.in.lua index 8143e35d4..02597b17c 100644 --- a/src/spider.in.lua +++ b/src/spider.in.lua @@ -113,38 +113,26 @@ local Spider = require("Spider") local concatTbl = table.concat local cosmic = require("Cosmic"):singleton() local dbg = require("Dbg"):dbg() +local hook = require("Hook") local i18n = require("i18n") local lfs = require("lfs") local sort = table.sort local pack = (_VERSION == "Lua 5.1") and argsPack or table.pack -- luacheck: compat -local ignoreA = { - "^$", - "^%.$", - "^%$", - "^%%", - "^/bin/", - "^/bin$", - "^/sbin$", - "^/usr/bin$", - "^/usr/sbin$", - "^/usr/local/share/bin$", - "^/usr/lib/?", - "^/opt/local/bin$", -} - -- key: /opt/apps/gcc-4_8/mpich/3.1.1, -- path: /opt/apps/gcc-4_8/mpich/3.1.1/lib, i: nil, j: nil - +local keepA = {} +local ignoreA = {} +hook.apply("spiderPathFilter", keepA,ignoreA) -------------------------------------------------------------------------- -- Check path against the *ignoreT* table. Also it must be "in" dirA if -- dirA exists. -- @param path input path. -local function keepThisPath2(path, dirA) - dbg.start{"keepThisPath2(",path,", dirA)"} +local function l_keepThisPath(path, dirA) + dbg.start{"l_keepThisPath(",path,", dirA)"} if (dirA) then local match = false @@ -158,20 +146,28 @@ local function keepThisPath2(path, dirA) end if (not match) then dbg.print{"No match\n"} - dbg.fini("keepThisPath2") + dbg.fini("l_keepThisPath") return false end end + + for i = 1, #keepA do + if (path:find(keepA[i])) then + dbg.print{"In keepA list: path:",path,"\n"} + dbg.fini("l_keepThisPath") + return true + end + end for i = 1, #ignoreA do if (path:find(ignoreA[i])) then - dbg.print{"In ignore list\n"} - dbg.fini("keepThisPath2") + dbg.print{"In ignore list: path:",path,"\n"} + dbg.fini("l_keepThisPath") return false end end dbg.print{"Keep: true\n"} - dbg.fini("keepThisPath2") + dbg.fini("l_keepThisPath") return true end @@ -186,7 +182,7 @@ local function add2map(entry, tbl, dirA, moduleFn, kind, rmapT) for path in pairs(tbl) do local attr = lfs.attributes(path) local a = attr or {} - local keep = keepThisPath2(path,dirA) + local keep = l_keepThisPath(path,dirA) dbg.print{"path: ",path,", keep: ",keep,", attr.mode: ",a.mode,"\n"} if (keep and attr and attr.mode == "directory") then