Skip to content

Commit

Permalink
Correct file search to avoid resolving glob dir
Browse files Browse the repository at this point in the history
Correctly use "glob" Tcl command not to resolve glob character (like
"*") in directory, only in file name.

Fix modulepath file search when libtclenvmodules is disabled and
modulepath contains glob characters (like * or ?).
  • Loading branch information
xdelaruelle committed Apr 18, 2024
1 parent 9a9a3ba commit 8066602
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tcl/cache.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ proc getLimitedAccessesInDirectory {modpath} {
# only walk through directory content if its access is not limited
} else {
# get all elements found in directory (regular and dot files)
set direlt_list [glob -nocomplain $elt/*]
set direlt_list [glob -nocomplain -directory $elt *]
foreach eltindir [glob -nocomplain -types hidden -directory\
$elt -tails *] {
if {$eltindir ni {. ..}} {
Expand Down
9 changes: 6 additions & 3 deletions tcl/coll.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ proc findCollections {{coll *} {search glob} {swap_by_init 0} {errnomatch 0}\
set collfile $coll
# elsewhere collection is a name
} elseif {[isEnvVarDefined HOME]} {
set collfile $::env(HOME)/.module/$coll
set coll_dir [file join $::env(HOME) .module]
set coll_glob $coll
# find saved collections (matching target suffix). a target is a domain
# on which a collection is only valid. when a target is set, only the
# collections made for that target will be available to list and
Expand All @@ -126,18 +127,20 @@ proc findCollections {{coll *} {search glob} {swap_by_init 0} {errnomatch 0}\
set colltarget [getConf collection_target]
if {$colltarget ne {} && ([getState hiding_threshold] < 2 ||\
[currentState commandname] ne {savelist})} {
append collfile .$colltarget
append coll_glob .$colltarget
# add knowledge of collection target on description
append colldesc " (for target \"$colltarget\")"
}
set collfile [file join $coll_dir $coll_glob]
} else {
reportErrorAndExit {HOME not defined}
}

switch -- $search {
glob {
# glob excludes by default files starting with "."
if {[catch {set clist [glob -nocomplain $collfile]} errMsg]} {
if {[catch {set clist [glob -nocomplain -directory $coll_dir\
$coll_glob]} errMsg]} {
reportErrorAndExit "Cannot access collection directory.\n$errMsg"
} else {
set res {}
Expand Down
2 changes: 1 addition & 1 deletion tcl/modfind.tcl.in
Original file line number Diff line number Diff line change
Expand Up @@ -2523,7 +2523,7 @@ proc doesModuleHaveSym {mod} {
proc __getFilesInDirectory {dir fetch_dotversion} {
set dir_list [list]

set elt_list [glob -nocomplain $dir/*]
set elt_list [glob -nocomplain -directory $dir *]

# Add each element in the current directory to the list
foreach elt $elt_list {
Expand Down
56 changes: 56 additions & 0 deletions testsuite/modules.20-locate/160-glob-path.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
##############################################################################
# Modules Revision 3.0
# Providing a flexible user environment
#
# File: modules.20-locate/%M%
# Revision: %I%
# First Edition: 2024/04/18
# Last Mod.: %U%, %G%
#
# Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr
#
# Description: Testuite testsequence
# Command:
# Modulefiles: foo
# Sub-Command: avail, savelist, saveshow
#
# Comment: %C{
# Check no glob resolution of directory path occur
# }C%
#
##############################################################################

skip_if_quick_mode


#
# locate modulefiles
#

set mp "$env(TESTSUITEDIR)/mod*lefiles.4"
setenv_path_var MODULEPATH $mp

testouterr_cmd sh {avail -t foo/1.0} OK {}


#
# locate collections
#

setenv_var HOME [file join $ORIG_HOME hom*]
set collfile [file join $ORIG_HOME hom* default]

set tserr [err_coll_notfound $collfile]
testouterr_cmd sh "saveshow $collfile" ERR $tserr

set tserr [msg_no_named_coll]
testouterr_cmd sh {savelist -t default} OK $tserr

setenv_var HOME $ORIG_HOME


#
# Cleanup
#

reset_test_env

0 comments on commit 8066602

Please sign in to comment.