aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-06 15:25:08 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-06 15:25:22 -0800
commitf0fc8c0cf6b1961fc7142b69ce151925df92ddc8 (patch)
treeffbb9b1bf9dc9b28f78adcd5ba263686fec80662
parent467d6457f343143afe798c70d5c6f875c46794c2 (diff)
Added option to skip cache and piped stderr to /dev/null
-rw-r--r--files.lua23
-rw-r--r--files.moon14
2 files changed, 23 insertions, 14 deletions
diff --git a/files.lua b/files.lua
index 72ec63b..3f80cfb 100644
--- a/files.lua
+++ b/files.lua
@@ -33,11 +33,16 @@ Files.spoof = function(filename, contents)
_SPOOFED_FILES[filename] = contents
return filename
end
-Files.read = function(filename)
- do
- local file_contents = _FILE_CACHE[filename]
- if file_contents then
- return file_contents or nil
+Files.read = function(filename, skip_cache)
+ if skip_cache == nil then
+ skip_cache = nil
+ end
+ if not (skip_cache) then
+ do
+ local file_contents = _FILE_CACHE[filename]
+ if file_contents then
+ return file_contents or nil
+ end
end
end
if filename == 'stdin' or filename == '-' then
@@ -52,7 +57,9 @@ Files.read = function(filename)
end
local contents = file:read("*a")
file:close()
- _FILE_CACHE[filename] = contents
+ if not (skip_cache) then
+ _FILE_CACHE[filename] = contents
+ end
return contents or nil
end
local match, gsub
@@ -88,7 +95,7 @@ Files.list = function(path)
path
}
else
- _BROWSE_CACHE[path] = run_cmd('find -L "' .. path .. '" -not -path "*/\\.*" -type f') or false
+ _BROWSE_CACHE[path] = run_cmd('find -L "' .. path .. '" -not -path "*/\\.*" -type f 2>/dev/null') or false
end
end
return _BROWSE_CACHE[path]
@@ -162,7 +169,7 @@ if ok then
return _BROWSE_CACHE[path]
end
else
- if not (run_cmd('find . -maxdepth 0')) then
+ if not (run_cmd('find . -maxdepth 0 2>/dev/null')) then
local url
if jit then
url = 'https://github.com/spacewander/luafilesystem'
diff --git a/files.moon b/files.moon
index 4088980..477e51e 100644
--- a/files.moon
+++ b/files.moon
@@ -23,9 +23,10 @@ Files.spoof = (filename, contents)->
return filename
-- Read a file's contents
-Files.read = (filename)->
- if file_contents = _FILE_CACHE[filename]
- return file_contents or nil
+Files.read = (filename, skip_cache=nil)->
+ unless skip_cache
+ if file_contents = _FILE_CACHE[filename]
+ return file_contents or nil
if filename == 'stdin' or filename == '-'
contents = io.read('*a')
Files.spoof('stdin', contents)
@@ -35,7 +36,8 @@ Files.read = (filename)->
return nil unless file
contents = file\read("*a")
file\close!
- _FILE_CACHE[filename] = contents
+ unless skip_cache
+ _FILE_CACHE[filename] = contents
return contents or nil
{:match, :gsub} = string
@@ -59,7 +61,7 @@ Files.list = (path)->
local files
_BROWSE_CACHE[path] = if _SPOOFED_FILES[path] or path == 'stdin' or path == '-'
{path}
- else run_cmd('find -L "'..path..'" -not -path "*/\\.*" -type f') or false
+ else run_cmd('find -L "'..path..'" -not -path "*/\\.*" -type f 2>/dev/null') or false
return _BROWSE_CACHE[path]
ok, lfs = pcall(require, "lfs")
@@ -95,7 +97,7 @@ if ok
if f\match("^%./") then _BROWSE_CACHE[path][i] = f\sub(3)
return _BROWSE_CACHE[path]
else
- unless run_cmd('find . -maxdepth 0')
+ unless run_cmd('find . -maxdepth 0 2>/dev/null')
url = if jit
'https://github.com/spacewander/luafilesystem'
else 'https://github.com/keplerproject/luafilesystem'