util/datamanager.lua

changeset 2444
267d6482bac6
parent 2326
2804d81206d8
child 2583
cb1f9266130b
equal deleted inserted replaced
2443:b335ae55af77 2444:267d6482bac6
19 local error = error; 19 local error = error;
20 local next = next; 20 local next = next;
21 local t_insert = table.insert; 21 local t_insert = table.insert;
22 local append = require "util.serialization".append; 22 local append = require "util.serialization".append;
23 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; 24 local raw_mkdir;
25
26 if prosody.platform == "posix" then
27 raw_mkdir = require "util.pposix".mkdir; -- Doesn't trample on umask
28 else
29 raw_mkdir = require "lfs".mkdir;
30 end
25 31
26 module "datamanager" 32 module "datamanager"
27 33
28 ---- utils ----- 34 ---- utils -----
29 local encode, decode; 35 local encode, decode;
30 do 36 do
31 local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end }); 37 local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
32 38
33 decode = function (s) 39 decode = function (s)
34 return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes)); 40 return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes));
35 end 41 end
41 47
42 local _mkdir = {}; 48 local _mkdir = {};
43 local function mkdir(path) 49 local function mkdir(path)
44 path = path:gsub("/", path_separator); -- TODO as an optimization, do this during path creation rather than here 50 path = path:gsub("/", path_separator); -- TODO as an optimization, do this during path creation rather than here
45 if not _mkdir[path] then 51 if not _mkdir[path] then
46 lfs_mkdir(path); 52 raw_mkdir(path);
47 _mkdir[path] = true; 53 _mkdir[path] = true;
48 end 54 end
49 return path; 55 return path;
50 end 56 end
51 57

mercurial