From 363c7a8dd507c7445d8b59bb830268770961bce8 Mon Sep 17 00:00:00 2001 From: Godzil Date: Tue, 5 Sep 2017 15:01:00 +0100 Subject: [PATCH] Use file.exists instead of open/close when relevant --- httpserver-compile.lua | 3 +-- httpserver.lua | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/httpserver-compile.lua b/httpserver-compile.lua index 29b49a5..afbf8b9 100644 --- a/httpserver-compile.lua +++ b/httpserver-compile.lua @@ -3,8 +3,7 @@ -- Author: Marcos Kirsch local compileAndRemoveIfNeeded = function(f) - if file.open(f) then - file.close() + if file.exists(f) then print('Compiling:', f) node.compile(f) file.remove(f) diff --git a/httpserver.lua b/httpserver.lua index a244335..65b4bc8 100644 --- a/httpserver.lua +++ b/httpserver.lua @@ -61,19 +61,19 @@ return function (port) uri.args = {code = 400, errorString = "Bad Request", logFunction = log} fileServeFunction = dofile("httpserver-error.lc") else - local fileExists = file.open(uri.file, "r") - file.close() + local fileExists = false - if not fileExists then + if not file.exists(uri.file) then + -- print(uri.file .. " not found, checking gz version...") -- gzip check - fileExists = file.open(uri.file .. ".gz", "r") - file.close() - - if fileExists then - --print("gzip variant exists, serving that one") + if file.exists(uri.file .. ".gz") then + -- print("gzip variant exists, serving that one") uri.file = uri.file .. ".gz" uri.isGzipped = true + fileExists = true end + else + fileExists = true end if not fileExists then