[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
PATCH: fix bug in getdirs
From: |
Ben Elliston |
Subject: |
PATCH: fix bug in getdirs |
Date: |
Mon, 10 Dec 2018 07:52:49 +1100 |
User-agent: |
NeoMutt/20170609 (1.8.3) |
I discovered a quite nasty bug in getdirs. I'm surprised it has never
caused a major problem before. When looking for directories that match
a pattern, the existing code uses 'catch' to avoid an error if nothing
matches the glob. The output is saved in $tmp. When nothing matches,
the error output is saved instead:
% glob /not/here
no files matched glob pattern "/not/here"
% catch {glob /not/here} tmp
1
% puts $tmp
no files matched glob pattern "/not/here"
This is wrong. Instead, we should use glob -nocomplain. This sets $tmp
to empty if there are no matches. In addition, I see no reason why
getdirs should call perror if there are no matches--this path was
never executed before, of course. Being a utility procedure, it is
fine to return "" and let the caller decide what to do.
I removed the if { $tmp ne "" } and else expressions and
reindented. The diff output below was generated with 'git diff
-w'.
OK?
Cheers, Ben
diff --git a/lib/utils.exp b/lib/utils.exp
index 57a6831..d397679 100644
--- a/lib/utils.exp
+++ b/lib/utils.exp
@@ -44,8 +44,7 @@ proc getdirs { args } {
set pattern "*"
}
verbose "Looking in $path for directories that match \"${pattern}\"" 3
- catch "glob $path/$pattern" tmp
- if { $tmp ne "" } {
+ set tmp [glob -nocomplain $path/$pattern]
foreach i $tmp {
if {[file isdirectory $i]} {
switch -- "[file tail $i]" {
@@ -72,10 +71,6 @@ proc getdirs { args } {
}
}
}
- } else {
- perror $tmp
- return ""
- }
if {![info exists dirs]} {
return ""
signature.asc
Description: PGP signature
- PATCH: fix bug in getdirs,
Ben Elliston <=