-
Notifications
You must be signed in to change notification settings - Fork 25
Excessive file type checking when running scripts #67
Comments
Also, later on in the file there's that big block of Original code:
Possible solution:
The commented out I'm not sure why it's checking for
|
Oh, and apparently https://ruby-doc.org/core-2.5.0/File.html#method-c-exists-3F |
Ok, this causes a really weird error. I had like 50+ copies of bootstrap and common-healing2 running and lich was grindingly slow.
Separating the 2 sections into their own
This latest change now allows me to run scripts with a partial name again ( |
Now that I think about it, I think the purpose of having both of these sections, instead of just the 1 with the case insensitive flag, is so that lich can differentiate between say
|
When looking for scripts in the ./scripts and ./scripts/custom folder, lich is looking for the following extensions:
.lic, .rb, .cmd, .wiz, .lic.gz, .rb.gz, .cmd.gz, .wiz.gz, .lic.z, .rb.z, .cmd.z, and .wiz.z
This seems excessive. The following block of code for matching the file name is also very convoluted. It seems like it could be cut in half.
file_list
in the above block of code is:file_list = Dir.children(File.join(SCRIPT_DIR, "custom")).map{ |s| s.prepend("/custom/") } + Dir.children(SCRIPT_DIR)
There are 3 sections to it. The first find block is checking if any of the files match either of these 2 patterns:
/^(?:\/custom\/)?#{Regexp.escape(script_name)}\.(?:lic|rb|cmd|wiz)(?:\.gz|\.Z)?$/
/^(?:\/custom\/)?#{Regexp.escape(script_name)}\.(?:lic|rb|cmd|wiz)(?:\.gz|\.Z)?$/i
I am unsure why these two are both needed. It seems like the second with the insensitive tag would match anything that the first one would match.
Then the next find block is checking if the file name matches this pattern:
/^(?:\/custom\/)?#{Regexp.escape(script_name)}[^.]+\.(?i:lic|rb|cmd|wiz)(?:\.gz|\.Z)?$/
And then the last find block checks for this pattern:
/^(?:\/custom\/)?#{Regexp.escape(script_name)}[^.]+\.(?:lic|rb|cmd|wiz)(?:\.gz|\.Z)?$/i
The only differences between these two are that in the first one the extension (lic, rb, cmd, and wiz) are a case insensitive check, and in the second one the whole pattern is case insensitive.
These last two blocks allow for matching partial script names so you can run
;repos
and it'll find repository.licIn trying to consolidate these, I came up with this. I was trying to make it so that you could run a script with the extension
;repository.lic
. Currently if you do that, it will say script not found. In doing so, I forgot about running scripts with partial filenames. Here is what I had come up with for that:if file_name = ( file_list.find { |val| val =~ /^(?:\/custom\/)?#{Regexp.escape(script_name)}(?:\.lic|\.rb|\.cmd|\.wiz)?(?:\.gz|\.Z)?$/i } )
This does allow you to run any script with or without its extension, but it won't allow you to run a partial script name.
I think this captures all possible cases:
if file_name = ( file_list.find { |val| val =~ /^(?:\/custom\/)?#{Regexp.escape(script_name)}(?:\.lic|\.rb|\.cmd|\.wiz)?(?:\.gz|\.Z)?$/i || val =~ /^(?:\/custom\/)?#{Regexp.escape(script_name)}[^.]+\.(?:lic|rb|cmd|wiz)(?:\.gz|\.Z)?$/i } )
It could use some more eyes on it though.
The text was updated successfully, but these errors were encountered: