tools/migration/migrator/prosody_files.lua
changeset 4239 69fe5fd861e7
parent 4216 ff80a8471e86
child 4241 49b9e73e31ef
equal deleted inserted replaced
4237:6b0d7d94eb7f 4239:69fe5fd861e7
    20 module "prosody_files"
    20 module "prosody_files"
    21 
    21 
    22 local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end
    22 local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end
    23 local function is_file(path) return lfs.attributes(path, "mode") == "file"; end
    23 local function is_file(path) return lfs.attributes(path, "mode") == "file"; end
    24 local function clean_path(path)
    24 local function clean_path(path)
    25 	return path:gsub("\\", "/"):gsub("//+", "/");
    25 	return path:gsub("\\", "/"):gsub("//+", "/"):gsub("^~", os.getenv("HOME") or "~");
    26 end
    26 end
    27 local encode, decode; do
    27 local encode, decode; do
    28 	local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
    28 	local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
    29 	decode = function (s) return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes)); end
    29 	decode = function (s) return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes)); end
    30 	encode = function (s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end
    30 	encode = function (s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end