add file exists checking in my_uuid
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
local _M = {}
|
||||
|
||||
function _M.file_exists(name)
|
||||
local f = io.open(name, "r")
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return _M
|
||||
+15
-6
@@ -1,14 +1,23 @@
|
||||
local commons = require("lib.commons")
|
||||
|
||||
local _M = {}
|
||||
|
||||
function _M.uuid()
|
||||
local uuid_cmd = "/usr/bin/uuid"
|
||||
|
||||
local handle = io.popen(uuid_cmd)
|
||||
local result = handle:read("*a")
|
||||
local r2 = string.gsub(result, "%s+", "")
|
||||
local r3 = string.gsub(r2,"\n","")
|
||||
ngx.log(ngx.INFO, "uuid -> ", r3)
|
||||
return r3
|
||||
if commons.file_exists(uuid_cmd) then
|
||||
local handle = io.popen(uuid_cmd)
|
||||
local result = handle:read("*a")
|
||||
local r2 = string.gsub(result, "%s+", "")
|
||||
local r3 = string.gsub(r2,"\n","")
|
||||
ngx.log(ngx.INFO, "uuid -> ", r3)
|
||||
return r3
|
||||
else
|
||||
ngx.status = 500
|
||||
ngx.log(ngx.ERR, "my_uuid *FAILED* `/usr/bin/uuid` not exists!")
|
||||
ngx.say("my_uuid *FAILED* `/usr/bin/uuid` not exists!")
|
||||
ngx.exit()
|
||||
end
|
||||
end
|
||||
|
||||
return _M
|
||||
Reference in New Issue
Block a user