Skip to content

Commit e0d8f82

Browse files
committed
Get rid of io module.
In tarantool the standart built-in module for working with files is "fio". So we should use it instead of "io".
1 parent fa999df commit e0d8f82

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

http/router/fs.lua

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local mime_types = require('http.mime_types')
44
local response = require('http.router.response')
55

66
local json = require('json')
7+
local fio = require('fio')
78

89
local function type_by_format(fmt)
910
if fmt == nil then
@@ -62,14 +63,19 @@ local function static_file(self, request, format)
6263
}
6364
end
6465

65-
local s, fh = pcall(io.input, file)
66+
local fh, err = fio.open(file, {'O_RDONLY'})
6667

67-
if not s then
68+
if err ~= nil then
6869
return { status = 404 }
6970
end
7071

71-
local body = fh:read('*a')
72-
io.close(fh)
72+
local body
73+
body, err = fh:read()
74+
if err ~= nil then
75+
utils.errorf("Can not return static file for '%s': '%s'", request:path(), err)
76+
end
77+
78+
fh:close()
7379

7480
if self.options.cache_static then
7581
self.cache.static[ file ] = body
@@ -158,8 +164,18 @@ local function load_template(self, r, format)
158164

159165

160166
local tpl = catfile(self.options.app_dir, 'templates', file)
161-
local fh = io.input(tpl)
162-
local template = fh:read('*a')
167+
local fh, err = fio.open(tpl)
168+
if err ~= nil then
169+
utils.errorf("Can not load template for '%s': '%s'", r.path, err)
170+
end
171+
172+
local template
173+
template, err = fh:read()
174+
175+
if err ~= nil then
176+
utils.errorf("Can not load template for '%s': '%s'", r.path, err)
177+
end
178+
163179
fh:close()
164180

165181
if self.options.cache_templates then

0 commit comments

Comments
 (0)