Use file.exists instead of open/close when relevant

This commit is contained in:
Godzil 2017-09-05 15:01:00 +01:00
parent b5baf6cd48
commit 363c7a8dd5
No known key found for this signature in database
GPG Key ID: F50075BABA34048B
2 changed files with 9 additions and 10 deletions

View File

@ -3,8 +3,7 @@
-- Author: Marcos Kirsch -- Author: Marcos Kirsch
local compileAndRemoveIfNeeded = function(f) local compileAndRemoveIfNeeded = function(f)
if file.open(f) then if file.exists(f) then
file.close()
print('Compiling:', f) print('Compiling:', f)
node.compile(f) node.compile(f)
file.remove(f) file.remove(f)

View File

@ -61,19 +61,19 @@ return function (port)
uri.args = {code = 400, errorString = "Bad Request", logFunction = log} uri.args = {code = 400, errorString = "Bad Request", logFunction = log}
fileServeFunction = dofile("httpserver-error.lc") fileServeFunction = dofile("httpserver-error.lc")
else else
local fileExists = file.open(uri.file, "r") local fileExists = false
file.close()
if not fileExists then if not file.exists(uri.file) then
-- print(uri.file .. " not found, checking gz version...")
-- gzip check -- gzip check
fileExists = file.open(uri.file .. ".gz", "r") if file.exists(uri.file .. ".gz") then
file.close() -- print("gzip variant exists, serving that one")
if fileExists then
--print("gzip variant exists, serving that one")
uri.file = uri.file .. ".gz" uri.file = uri.file .. ".gz"
uri.isGzipped = true uri.isGzipped = true
fileExists = true
end end
else
fileExists = true
end end
if not fileExists then if not fileExists then