Software /
code /
prosody
Comparison
util/datamanager.lua @ 2159:2ef4458b23d9
util.datamanager: Replace popen(mkdir) with lfs.mkdir, keeping the just-in-time creation until we have the new datamanager API
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 23 Nov 2009 20:18:04 +0000 |
parent | 1732:f1282fad2f99 |
child | 2328:2804d81206d8 |
child | 2923:b7049746bd29 |
comparison
equal
deleted
inserted
replaced
2158:575d5db7f14f | 2159:2ef4458b23d9 |
---|---|
13 local char = string.char; | 13 local char = string.char; |
14 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; | 14 local loadfile, setfenv, pcall = loadfile, setfenv, pcall; |
15 local log = require "util.logger".init("datamanager"); | 15 local log = require "util.logger".init("datamanager"); |
16 local io_open = io.open; | 16 local io_open = io.open; |
17 local os_remove = os.remove; | 17 local os_remove = os.remove; |
18 local io_popen = io.popen; | |
19 local tostring, tonumber = tostring, tonumber; | 18 local tostring, tonumber = tostring, tonumber; |
20 local error = error; | 19 local error = error; |
21 local next = next; | 20 local next = next; |
22 local t_insert = table.insert; | 21 local t_insert = table.insert; |
23 local append = require "util.serialization".append; | 22 local append = require "util.serialization".append; |
24 local path_separator = "/"; if os.getenv("WINDIR") then path_separator = "\\" end | 23 local path_separator = "/"; if os.getenv("WINDIR") then path_separator = "\\" end |
24 local lfs_mkdir = require "lfs".mkdir; | |
25 | 25 |
26 module "datamanager" | 26 module "datamanager" |
27 | 27 |
28 ---- utils ----- | 28 ---- utils ----- |
29 local encode, decode; | 29 local encode, decode; |
41 | 41 |
42 local _mkdir = {}; | 42 local _mkdir = {}; |
43 local function mkdir(path) | 43 local function mkdir(path) |
44 path = path:gsub("/", path_separator); -- TODO as an optimization, do this during path creation rather than here | 44 path = path:gsub("/", path_separator); -- TODO as an optimization, do this during path creation rather than here |
45 if not _mkdir[path] then | 45 if not _mkdir[path] then |
46 local x = io_popen("mkdir \""..path.."\" 2>&1"):read("*a"); | 46 lfs_mkdir(path); |
47 _mkdir[path] = true; | 47 _mkdir[path] = true; |
48 end | 48 end |
49 return path; | 49 return path; |
50 end | 50 end |
51 | 51 |