Skip to content

Commit ab9a5d3

Browse files
Godzilmarcoskirsch
authored andcommitted
Use file.exists instead of open/close when relevant (marcoskirsch#112)
1 parent 6158d4b commit ab9a5d3

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

httpserver-compile.lua

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
-- Author: Marcos Kirsch
44

55
local compileAndRemoveIfNeeded = function(f)
6-
if file.open(f) then
7-
file.close()
6+
if file.exists(f) then
87
print('Compiling:', f)
98
node.compile(f)
109
file.remove(f)

httpserver.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ return function (port)
6161
uri.args = {code = 400, errorString = "Bad Request", logFunction = log}
6262
fileServeFunction = dofile("httpserver-error.lc")
6363
else
64-
local fileExists = file.open(uri.file, "r")
65-
file.close()
64+
local fileExists = false
6665

67-
if not fileExists then
66+
if not file.exists(uri.file) then
67+
-- print(uri.file .. " not found, checking gz version...")
6868
-- gzip check
69-
fileExists = file.open(uri.file .. ".gz", "r")
70-
file.close()
71-
72-
if fileExists then
73-
--print("gzip variant exists, serving that one")
69+
if file.exists(uri.file .. ".gz") then
70+
-- print("gzip variant exists, serving that one")
7471
uri.file = uri.file .. ".gz"
7572
uri.isGzipped = true
73+
fileExists = true
7674
end
75+
else
76+
fileExists = true
7777
end
7878

7979
if not fileExists then

0 commit comments

Comments
 (0)