Updated package.nomsupath behavior to first search the installed
locations, *then* search the current directory. This makes the system `nomsu` run properly, even if the local directory has a broken file that has the same name as a nomsu file.
This commit is contained in:
parent
3cf97066be
commit
b6c99c56a1
74
files.lua
74
files.lua
@ -1,6 +1,7 @@
|
||||
local lpeg = require('lpeg')
|
||||
local re = require('re')
|
||||
local Files = { }
|
||||
assert(package.nomsupath, "No package.nomsupath was found")
|
||||
local _SPOOFED_FILES = { }
|
||||
local _FILE_CACHE = setmetatable({ }, {
|
||||
__index = _SPOOFED_FILES
|
||||
@ -21,14 +22,6 @@ Files.read = function(filename)
|
||||
return Files.spoof('stdin', io.read('*a'))
|
||||
end
|
||||
local file = io.open(filename)
|
||||
if package.nomsupath and not file then
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
file = io.open(nomsupath .. "/" .. filename)
|
||||
if file then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not (file) then
|
||||
return nil
|
||||
end
|
||||
@ -57,11 +50,9 @@ Files.exists = function(path)
|
||||
if not (io.popen("ls " .. tostring(sanitize(path))):close()) then
|
||||
return true
|
||||
end
|
||||
if package.nomsupath then
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
if not (io.popen("ls " .. tostring(nomsupath) .. "/" .. tostring(sanitize(path))):close()) then
|
||||
return true
|
||||
end
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
if not (io.popen("ls " .. tostring(nomsupath) .. "/" .. tostring(sanitize(path))):close()) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
@ -75,16 +66,24 @@ browse = function(path)
|
||||
path
|
||||
}
|
||||
else
|
||||
local f = io.popen('find -L "' .. package.nomsupath .. '/' .. path .. '" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||
do
|
||||
local _tbl_0 = { }
|
||||
for line in f:lines() do
|
||||
local _key_0, _val_0 = line
|
||||
_tbl_0[_key_0] = _val_0
|
||||
local result = false
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
local f = io.popen('find -L "' .. nomsupath .. '/' .. path .. '" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||
do
|
||||
local _accum_0 = { }
|
||||
local _len_0 = 1
|
||||
for line in f:lines() do
|
||||
_accum_0[_len_0] = line
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
files = _accum_0
|
||||
end
|
||||
if f:close() then
|
||||
result = files
|
||||
break
|
||||
end
|
||||
files = _tbl_0
|
||||
end
|
||||
_BROWSE_CACHE[path] = f:close() and files or false
|
||||
_BROWSE_CACHE[path] = result
|
||||
end
|
||||
end
|
||||
return _BROWSE_CACHE[path]
|
||||
@ -107,11 +106,9 @@ if ok then
|
||||
if path == 'stdin' or raw_file_exists(path) then
|
||||
return true
|
||||
end
|
||||
if package.nomsupath then
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
if raw_file_exists(nomsupath .. "/" .. path) then
|
||||
return true
|
||||
end
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
if raw_file_exists(nomsupath .. "/" .. path) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
@ -139,12 +136,21 @@ if ok then
|
||||
elseif file_type == 'directory' or file_type == 'link' then
|
||||
local files = { }
|
||||
for subfile in lfs.dir(filename) do
|
||||
if not (subfile == "." or subfile == "..") then
|
||||
local _continue_0 = false
|
||||
repeat
|
||||
if subfile == "." or subfile == ".." then
|
||||
_continue_0 = true
|
||||
break
|
||||
end
|
||||
local _list_0 = (browse(filename .. "/" .. subfile) or { })
|
||||
for _index_0 = 1, #_list_0 do
|
||||
local f = _list_0[_index_0]
|
||||
files[#files + 1] = f
|
||||
end
|
||||
_continue_0 = true
|
||||
until true
|
||||
if not _continue_0 then
|
||||
break
|
||||
end
|
||||
end
|
||||
_BROWSE_CACHE[filename] = files
|
||||
@ -167,14 +173,12 @@ Files.walk = function(path, flush_cache)
|
||||
if flush_cache then
|
||||
_BROWSE_CACHE = { }
|
||||
end
|
||||
local files = browse(path)
|
||||
if package.nomsupath and not files then
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
do
|
||||
files = browse(nomsupath .. "/" .. path)
|
||||
if files then
|
||||
break
|
||||
end
|
||||
local files
|
||||
for nomsupath in package.nomsupath:gmatch("[^;]+") do
|
||||
do
|
||||
files = browse(nomsupath .. "/" .. path)
|
||||
if files then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
39
files.moon
39
files.moon
@ -2,6 +2,7 @@
|
||||
lpeg = require 'lpeg'
|
||||
re = require 're'
|
||||
Files = {}
|
||||
assert package.nomsupath, "No package.nomsupath was found"
|
||||
|
||||
_SPOOFED_FILES = {}
|
||||
_FILE_CACHE = setmetatable {}, __index:_SPOOFED_FILES
|
||||
@ -19,10 +20,6 @@ Files.read = (filename)->
|
||||
if filename == 'stdin'
|
||||
return Files.spoof('stdin', io.read('*a'))
|
||||
file = io.open(filename)
|
||||
if package.nomsupath and not file
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
file = io.open(nomsupath.."/"..filename)
|
||||
break if file
|
||||
return nil unless file
|
||||
contents = file\read("*a")
|
||||
file\close!
|
||||
@ -43,9 +40,8 @@ sanitize = (path)->
|
||||
Files.exists = (path)->
|
||||
return true if _SPOOFED_FILES[path]
|
||||
return true unless io.popen("ls #{sanitize(path)}")\close!
|
||||
if package.nomsupath
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
return true unless io.popen("ls #{nomsupath}/#{sanitize(path)}")\close!
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
return true unless io.popen("ls #{nomsupath}/#{sanitize(path)}")\close!
|
||||
return false
|
||||
|
||||
browse = (path)->
|
||||
@ -54,9 +50,14 @@ browse = (path)->
|
||||
_BROWSE_CACHE[path] = if _SPOOFED_FILES[path]
|
||||
{path}
|
||||
else
|
||||
f = io.popen('find -L "'..package.nomsupath..'/'..path..'" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||
files = {line for line in f\lines!}
|
||||
f\close! and files or false
|
||||
result = false
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
f = io.popen('find -L "'..nomsupath..'/'..path..'" -not -path "*/\\.*" -type f -name "*.nom"')
|
||||
files = [line for line in f\lines!]
|
||||
if f\close!
|
||||
result = files
|
||||
break
|
||||
result
|
||||
return _BROWSE_CACHE[path]
|
||||
|
||||
ok, lfs = pcall(require, "lfs")
|
||||
@ -67,9 +68,8 @@ if ok
|
||||
Files.exists = (path)->
|
||||
return true if _SPOOFED_FILES[path]
|
||||
return true if path == 'stdin' or raw_file_exists(path)
|
||||
if package.nomsupath
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
return true if raw_file_exists(nomsupath.."/"..path)
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
return true if raw_file_exists(nomsupath.."/"..path)
|
||||
return false
|
||||
|
||||
export browse
|
||||
@ -88,9 +88,9 @@ if ok
|
||||
elseif file_type == 'directory' or file_type == 'link'
|
||||
files = {}
|
||||
for subfile in lfs.dir(filename)
|
||||
unless subfile == "." or subfile == ".."
|
||||
for f in *(browse(filename.."/"..subfile) or {})
|
||||
files[#files+1] = f
|
||||
continue if subfile == "." or subfile == ".."
|
||||
for f in *(browse(filename.."/"..subfile) or {})
|
||||
files[#files+1] = f
|
||||
files
|
||||
else false
|
||||
return _BROWSE_CACHE[filename]
|
||||
@ -102,10 +102,9 @@ Files.walk = (path, flush_cache=false)->
|
||||
if flush_cache
|
||||
export _BROWSE_CACHE
|
||||
_BROWSE_CACHE = {}
|
||||
files = browse(path)
|
||||
if package.nomsupath and not files
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
if files = browse(nomsupath.."/"..path) then break
|
||||
local files
|
||||
for nomsupath in package.nomsupath\gmatch("[^;]+")
|
||||
if files = browse(nomsupath.."/"..path) then break
|
||||
iter = (files, i)->
|
||||
return unless files
|
||||
i += 1
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env nomsu -V2.5.4.3
|
||||
# This file sets the current library version.
|
||||
lua> "NOMSU_LIB_VERSION = 3"
|
||||
lua> "NOMSU_LIB_VERSION = 4"
|
||||
|
@ -48,7 +48,9 @@ if NOMSU_VERSION and NOMSU_PREFIX then
|
||||
_len_0 = _len_0 + 1
|
||||
end
|
||||
return _accum_0
|
||||
end)(), ";")
|
||||
end)(), ";") .. ";."
|
||||
else
|
||||
package.nomsupath = "."
|
||||
end
|
||||
local EXIT_SUCCESS, EXIT_FAILURE = 0, 1
|
||||
local usage = [=[Nomsu Compiler
|
||||
|
@ -5,7 +5,9 @@ if NOMSU_VERSION and NOMSU_PREFIX
|
||||
partial_vers = [table.concat(ver_bits,'.',1,i) for i=#ver_bits,1,-1]
|
||||
package.path = table.concat(["#{NOMSU_PREFIX}/share/nomsu/#{v}/?.lua" for v in *partial_vers],";")..";"..package.path
|
||||
package.cpath = table.concat(["#{NOMSU_PREFIX}/lib/nomsu/#{v}/?.so" for v in *partial_vers],";")..";"..package.cpath
|
||||
package.nomsupath = table.concat(["#{NOMSU_PREFIX}/share/nomsu/#{v}" for v in *partial_vers],";")
|
||||
package.nomsupath = table.concat(["#{NOMSU_PREFIX}/share/nomsu/#{v}" for v in *partial_vers],";")..";."
|
||||
else
|
||||
package.nomsupath = "."
|
||||
|
||||
EXIT_SUCCESS, EXIT_FAILURE = 0, 1
|
||||
usage = [=[
|
||||
|
@ -158,7 +158,7 @@ local NomsuCompiler = setmetatable({ }, {
|
||||
end
|
||||
})
|
||||
do
|
||||
NomsuCompiler.NOMSU_COMPILER_VERSION = 4
|
||||
NomsuCompiler.NOMSU_COMPILER_VERSION = 5
|
||||
NomsuCompiler.NOMSU_SYNTAX_VERSION = Parser.version
|
||||
NomsuCompiler._ENV = NomsuCompiler
|
||||
NomsuCompiler.nomsu = NomsuCompiler
|
||||
@ -454,7 +454,7 @@ do
|
||||
if not (ran_lua) then
|
||||
local file = Files.read(filename)
|
||||
if not file then
|
||||
error("File does not exist: " .. tostring(filename), 0)
|
||||
error("Tried to run file that does not exist: " .. tostring(filename))
|
||||
end
|
||||
ret = self:run(file, Source(filename, 1, #file))
|
||||
end
|
||||
|
@ -95,7 +95,7 @@ dict = (t)-> setmetatable(t, _dict_mt)
|
||||
MAX_LINE = 80 -- For beautification purposes, try not to make lines much longer than this value
|
||||
NomsuCompiler = setmetatable({}, {__index: (k)=> if _self = rawget(@, "self") then _self[k] else nil})
|
||||
with NomsuCompiler
|
||||
.NOMSU_COMPILER_VERSION = 4
|
||||
.NOMSU_COMPILER_VERSION = 5
|
||||
.NOMSU_SYNTAX_VERSION = Parser.version
|
||||
._ENV = NomsuCompiler
|
||||
.nomsu = NomsuCompiler
|
||||
@ -260,6 +260,7 @@ with NomsuCompiler
|
||||
|
||||
_running_files = {} -- For detecting circular imports
|
||||
.run_file = (filename)=>
|
||||
-- Filename should be an absolute path, i.e. package.nomsupath will not be searched for it
|
||||
if @LOADED[filename]
|
||||
return @LOADED[filename]
|
||||
-- Check for circular import
|
||||
@ -284,7 +285,7 @@ with NomsuCompiler
|
||||
unless ran_lua
|
||||
file = Files.read(filename)
|
||||
if not file
|
||||
error("File does not exist: #{filename}", 0)
|
||||
error("Tried to run file that does not exist: #{filename}")
|
||||
ret = @run file, Source(filename,1,#file)
|
||||
else
|
||||
error("Invalid filetype for #{filename}", 0)
|
||||
|
Loading…
Reference in New Issue
Block a user