util/datamanager.lua

changeset 2279
27441b099984
parent 2157
2ef4458b23d9
child 2326
2804d81206d8
child 2923
b7049746bd29
equal deleted inserted replaced
2278:0b0fe49e5251 2279:27441b099984
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

mercurial