Commit Graph

504 Commits

Author SHA1 Message Date
Xavier Delaruelle
09e6bc74f4 Fix shell alias translation with fish shell 3.6
A '$argv' string is added in fish 3.6 at the end of shell alias
definition when reported with functions command.
2023-01-24 05:59:18 +01:00
Xavier Delaruelle
98af688203 Catch collection dir error and report correct msg
Fixes #482
2023-01-16 19:43:04 +01:00
Xavier Delaruelle
a89c60fee0 Correctly apply extra tag when variant not set
Correctly apply extra tag set when loading a module whose variant has no
specific value set (default value used).

Fixes #484
2023-01-16 19:42:54 +01:00
Xavier Delaruelle
748fe9ca9d Resolve limited access files/dirs when using cache
When searching modules through cache files resolve files and directories
marked as limited access. First check such entries match the search
query, then test if these files and directories can be accessed by
current user.

The access test relies on the findModulesFromDirsAndFiles procedure, as
if module search was not performed with cache file, but just for the
limited-access entries.
2022-12-27 18:43:59 +01:00
Xavier Delaruelle
e08fb48465 Create findModulesFromDirsAndFiles from findModules
Split code from findModules procedure that walk through a list of files
and directories to find modules. Create a new procedure named
findModulesFromDirsAndFiles for that purpose.

This new procedure will be helpful to resolve limited access files and
directories spotted in cache file.
2022-12-27 18:43:59 +01:00
Xavier Delaruelle
8c2218617f Add limited-access-directory cachefile command
Add limited-access-directory cachefile command to record all directories
with limited access in modulepath.
2022-12-27 18:43:59 +01:00
Xavier Delaruelle
44e27b7077 Add limited-access-file cachefile command
Add limited-access-file cachefile command to record all files with
limited access in modulepath.
2022-12-27 18:43:59 +01:00
Xavier Delaruelle
d5bdf7d173 Register files/dir with limited access in cache
When building cache, check all files and directory within modulepath
that have limited access. Limited access is when user building cache or
others cannot read file or cannot either read or search directory.

Limited access file or directory are recorded in cache file with
respectively limited-access-file and limited-access-directory cachefile
commands.

Limited access commands replace modulefile/modulerc definitions in the
cache if files or their parent directory has limited access.
2022-12-27 18:43:59 +01:00
Xavier Delaruelle
19058a95eb Introduce cache_expiry_secs configuration option
Add cache_expiry_secs configuration option to control after how many
seconds (after last modification) to consider cache file expired and
ignore it. Set to 0 by default which means cache file never expires.
Value can vary from 0 to 31536000 which corresponds to the number of
seconds during one year.

When configuration option is set, it defies the
MODULES_CACHE_EXPIRY_SECS environment variable.
2022-12-27 18:43:59 +01:00
Xavier Delaruelle
d70bdb1835 Introduce cache_buffer_bytes configuration option
Add cache_buffer_bytes configuration option to control the buffer size
used when reading or writing cache files. A 32 kbytes buffer is set by
default. It can vary from 4 kbytes to 1 MB. It is useful to have a large
buffer when reading or writing large files to reduce the number or read
or write system calls.

When configuration option is set, it defies the
MODULES_CACHE_BUFFER_BYTES environment variable.
2022-12-27 18:43:58 +01:00
Xavier Delaruelle
e21b8fa57b Add specific proc to read cache file
Introduce readCacheContent procedure to specifically read cache file
rather using read procedure for modulefile. Avoid cache file to be
cached in memory. Produce more specific error message.
2022-12-27 18:43:58 +01:00
Xavier Delaruelle
ac861b2ca7 Ignore cache file when ignore_cache enabled
Do not check or evaluate cache file if ignore_cache option is enabled.

Use this new option in cachebuild sub-command to ignore cache when
building cache files.
2022-12-27 18:43:58 +01:00
Xavier Delaruelle
798af2d6e8 Add ignore_cache configuration option
Add ignore_cache configuration option that controls whether or not
module cache file should be considered if available. Disabled by
default. When configuration is modified it sets the MODULES_IGNORE_CACHE
environment variable.

--ignore-cache command line switch can be used to enable ignore_cache
for the current execution.

--ignore_cache is also supported for compatibility with Lmod.
2022-12-27 18:43:58 +01:00
Xavier Delaruelle
2ee7807439 Enable mcookie_check/mcookie_version_check on cachebuild
Enable both mcookie_check and mcookie_version_check configuration
options when recording cache. These two options are not honored when
building or using cache.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
d43db0a468 Revert optimization filter tries for findModulesInCacheFile
As the improvement obtained by either of these optimization methods was
not perceptible, they are withdrawn to keep filtering code simpler.

Gain was also not perceptible since the additional cost taken by cache
was not perceptible in the first place.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
5e1ecd052f Second optimization filter try for findModulesInCacheFile
As first try is not 100% accurate since it does not compare element root
names. This second attempt first compute the list of element root names
to compare, same lsearch -glob mechanism for comparison. Then unset
elements whose root name has been returned by comparison.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
7451de819f Optimize module filtering in findModulesInCacheFile
Increase filtering performance in findModulesInCacheFile: instead of
testing for match each module in cache through modEqStatic, gets all
module to exclude from result at once with lsearch command.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
5446e3f552 Distinguish empty cache result from no cache result
Update structure of result returned by findModulesInCacheFile to
indicate if cache load was successful or not. It is possible this way to
distinguish between a *there is no cache* result and a *no match in
cache* or *empty cache* results.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
83b79fdcb7 Cache content filer in findModulesInCacheFile
Add code in findModulesInCacheFile to filter fetched cache content to
tailor it to the search query. Proceed following what is done in
findModules procedure but in a reverse order (we remove elements from a
full structure, rather we add elements to an empty structure).
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
450a704c3e Set time string as separate arg on reportTimer
Avoid evaluating full message string to replace time pattern by
execution time value. Message could contain string that could be
misinterpreted by format command as time pattern.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
688136537f Add modulefile-invalid cachefile command
Add modulefile-invalid cachefile command used to record a invalid
modulefile in modulepath.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
1e3d824d76 Add modulerc-content cachefile command
Add modulerc-content cachefile command used to record a modulerc
available in modulepath. Record modulerc information in memory cache
variables: g_modfileContent.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
95ae893a13 Add modulefile-content cachefile command
Add modulefile-content cachefile command used to record a modulefile
available in modulepath. Record modulefile information in memory cache
variables: g_modfileContent and g_fileMtime.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
bf80dab461 Core code for execute-cachefile
Add core code for execute-cachefile procedure. Initialize an interpreter
to evaluate the cache file. Reuse the same mechanisms than for
modulefile or modulerc evaluation.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
4fc57482cf Add initial code structure to evaluate cache file
Add call to findModulesInCacheFile procedure in findModules to retrieve
available modulefile and modulerc information from modulepath cache
file.

findModulesInCacheFile tests a cache file is available and evaluate it
if not yet done with execute-cachefile procedure. Cache file information
will then be parsed to return the information matching the search query.

Initial code structure is inserted with this commit. Code for cache file
evaluation and cache information tailoring will come next.
2022-12-24 17:24:52 +01:00
Xavier Delaruelle
affeb8a994 Add major.minor version number in cache files
Append major.minor version number to the #%Module header prefix of
generated cache files. Cache file can be used only if generated for the current
release of Modules used.

Change cache.tcl into cache.tcl.in to get Modules release number
resolved at build time.
2022-11-30 08:07:12 +01:00
Xavier Delaruelle
9ceb82e914 Core code for formatModuleCacheContent
Implement formatModuleCacheContent procedure. findModules procedure is
first called to get all files from designated modulepath directory. A
cache entry is made for each result obtained from findModules with
cache file commands: modulefile-content, modulerc-content and
modulefile-invalid.

Goal is to record all information produced by findModules to be able to
replace findModules processing by cache file evaluation. Thus modulefile
modification time and validity check issues are recorded in cache file.

Modulerc and modulefile content is read and recorded as-is in cache
file. Error occurring during file read is raised and ends cache file
creation.
2022-11-30 08:07:12 +01:00
Xavier Delaruelle
61db5abf13 Core code for cmdModuleCachebuild
Implement cachebuild sub-command. For each modulepath enabled or passed
as argument, if modulepath is writable for user build cache content for
this modulepath and record it in cache file.

Report message block is used to report file creation. Reports are output
in normal verbosity level or higher. A warning message is emitted if
modulepath is not writable for user, or if cache content to create is
empty.

Provide empty skeleton for formatModuleCacheContent procedure.
2022-11-28 03:58:56 +01:00
Xavier Delaruelle
4c92b082d9 Core code for cmdModuleCacheclear
Implement cacheclear sub-command. For each modulepath enabled, check
module cache file exists. If yes and if modulepath is writable for user,
try to delete the cache file.

Report message block is used to report file deletion. Reports are output
in normal verbosity level or higher. A warning message is emitted if
modulepath is not writable for user.

Add tcl/cache.tcl source file to store procedure related to cache
mechanism. Update Makefile to properly generate modulecmd.tcl with this
new tcl file.
2022-11-28 03:58:56 +01:00
Xavier Delaruelle
b55e74480b Add 'cacheclear' sub-command
Introduce cacheclear sub-command to delete cache file under modulepaths.

This sub-command cannot be called from a modulefile evaluation context.

Add sub-command empty skeleton: cmdModuleCacheclear.

Sub-command accepts no option nor argument. Cache files are deleted in
every enabled modulepaths.
2022-11-28 03:58:56 +01:00
Xavier Delaruelle
b7d74702cc Add 'cachebuild' sub-command
Introduce cachebuild sub-command to create cache file under modulepaths.

This sub-command cannot be called from a modulefile evaluation context.

Add sub-command empty skeleton: cmdModuleCachebuild.

Sub-command accepts no option. It may take optional arguments: list of
modulepath directory where to build cache. When no argument is
specified, cache is built for all enabled modulepaths.
2022-11-12 13:15:54 +01:00
Xavier Delaruelle
c8e3bc392d Add hooks for specific vars/cmds in modulerc interp ctx
Introduce hooks to define specific variables and commands for modulerc
interpreter context. It relies on variables defined in siteconfig.tcl
configuration file:

* modulerc_extra_vars is a list of variable name and value pairs
* modulerc_extra_cmds is a list of command name and procedure pairs

Fixes #286
2022-11-01 20:30:37 +01:00
Xavier Delaruelle
edee6736df Add hooks for specific vars/cmds in modulefile interp ctx
Introduce hooks to define specific variables and commands for modulefile
interpreter context. It relies on variables defined in siteconfig.tcl
configuration file:

* modulefile_extra_vars is a list of variable name and value pairs
* modulefile_extra_cmds is a list of command name and procedure pairs

Fixes #286
2022-11-01 20:30:26 +01:00
Xavier Delaruelle
189461a1d5 Remove modvr default value on setLoadedModule proc 2022-10-31 13:18:58 +01:00
Xavier Delaruelle
424aa9013b Only refresh loaded modules requiring it
Use the qualified refresh property to only evaluate in refresh mode the
loaded modules marked with this property.

Fixes #477
2022-10-31 13:18:50 +01:00
Xavier Delaruelle
2828d78a89 Track loaded modules qualified for refresh eval
Track loaded modules that are qualified for a refresh evaluation.
Refresh evaluation is only useful if module defines volatile environment
changes: shell completion, alias or function.

An internal state, named refresh_qualified, marks loading modules
defining such volatile environment changes. Such modules are then added
to the __MODULES_LMREFRESH environment variable to track this property
once module is loaded.

Code is also added to remove module from __MODULES_LMREFRESH when it is
unloaded.
2022-10-30 20:38:01 +01:00
Xavier Delaruelle
39923ad178 Revert "init: setup zsh FPATH through autoinit command"
This reverts commit 59ac24e243.

FPATH variable cannot be handled within autoinit process as this is not
an environment variable. Thus when modulecmd.tcl is executed, it does
not know the current value of FPATH. So if it sets FPATH during
autoinit, previous value of this variable is lost. As a result FPATH
must stay defined in initialization script.
2022-10-16 14:06:11 +02:00
Xavier Delaruelle
b5d6ad81aa Filter stash collection on savelist
Update savelist sub-command to filter out stash collections unless --all
option is set.
2022-10-07 06:54:42 +02:00
Xavier Delaruelle
15591e5add Core code for cmdModuleStashlist
Implement 'stashlist' sub-command. Rely on cmdModuleSavelist but adapt
this procedure to make several behavior changes when called by
cmdModuleStashlist:

* elements are sorted in reverse order
* element index starts at 0
* when no collection target set, only return collection without a target
  set
2022-10-04 07:41:37 +02:00
Xavier Delaruelle
40867351c2 Add getCallingProcName util proc
Return name of calling procedure with getCallingProcName.
2022-10-04 07:41:37 +02:00
Xavier Delaruelle
43beec6df5 Add start_idx argument on displayElementList
Add start_idx argument on displayElementList procedure to define what is
the starting index for the elements to report.
2022-10-02 14:26:28 +02:00
Xavier Delaruelle
50e0bcbe3a Add 'stashlist' sub-command
Introduce stashlist sub-command to list stash collection file.

This sub-command cannot be called from a modulefile evaluation context.

Add sub-command empty skeleton: cmdModuleStashlist.

Sub-command accepts no argument. It accepts --terse, --long and --json
options.
2022-10-02 10:05:28 +02:00
Xavier Delaruelle
7fed10153c Core code for cmdModuleStashclear
Implement 'stashclear' sub-command. Fetch all existing stash collection
for current collection target. Then call 'saverm' sub-command over all
of these collection obtained.
2022-09-29 07:02:38 +02:00
Xavier Delaruelle
a98ccf1ca0 Add 'stashclear' sub-command
Introduce stashclear sub-command to delete all stash collection file.

This sub-command cannot be called from a modulefile evaluation context.

Add sub-command empty skeleton: cmdModuleStashclear.

Sub-command accepts no argument nor option.
2022-09-29 07:02:38 +02:00
Xavier Delaruelle
0e9d62e8f7 Core code for cmdModuleStashshow
Implement 'stashshow' sub-command. Parse stash argument to get
corresponding collection, then call saveshow over this collection name.
2022-09-29 07:02:38 +02:00
Xavier Delaruelle
9d539c4479 Add 'stashshow' sub-command
Introduce stashshow sub-command to display stash collection file.

This sub-command cannot be called from a modulefile evaluation context.

Add sub-command empty skeleton: cmdModuleStashshow.

Sub-command accepts no option. It may take an optional argument: the
index of the stash collection to display or the name of the stash
collection. If no argument is provided, stash collection 0 is assumed.
2022-09-28 07:21:30 +02:00
Xavier Delaruelle
07caa4594c Core code for cmdModuleStashrm
Implement 'stashrm' sub-command. Parse stash argument to get
corresponding collection, then call saverm over this collection name.
2022-09-28 07:21:30 +02:00
Xavier Delaruelle
66bd9e23b1 Move collection resolution from stash in dedicated proc
Move collection name resolution from stash name from cmdModuleStashpop
into getCollectionFromStash procedure.
2022-09-28 07:21:30 +02:00
Xavier Delaruelle
3358134471 Add 'stashrm' sub-command
Introduce stashrm sub-command to delete stash collection file.

This sub-command cannot be called from a modulefile evaluation context.

Add sub-command empty skeleton: cmdModuleStashrm.

Sub-command accepts no option. It may take an optional argument: the
index of the stash collection to delete or the name of the stash
collection. If no argument is provided, stash collection 0 is assumed.
2022-09-28 07:20:54 +02:00
Xavier Delaruelle
fc235534db Core code for cmdModuleStashpop
Implement 'stashpop' sub-command. First parse stash argument to
determine corresponding stash collection name or raise an error if stash
value is invalid. Then restore stash collection. Afterward delete stash
collection.
2022-09-28 07:20:54 +02:00