tools/migration/migrator/prosody_files.lua
changeset 4241 49b9e73e31ef
parent 4239 69fe5fd861e7
child 4293 419354c47c28
equal deleted inserted replaced
4240:b3d9063aad4d 4241:49b9e73e31ef
    11 local pcall = pcall;
    11 local pcall = pcall;
    12 local mtools = require "migrator.mtools";
    12 local mtools = require "migrator.mtools";
    13 local next = next;
    13 local next = next;
    14 local pairs = pairs;
    14 local pairs = pairs;
    15 local json = require "util.json";
    15 local json = require "util.json";
       
    16 local os_getenv = os.getenv;
    16 
    17 
    17 prosody = {};
    18 prosody = {};
    18 local dm = require "util.datamanager"
    19 local dm = require "util.datamanager"
    19 
    20 
    20 module "prosody_files"
    21 module "prosody_files"
    21 
    22 
    22 local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end
    23 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
    24 local function is_file(path) return lfs.attributes(path, "mode") == "file"; end
    24 local function clean_path(path)
    25 local function clean_path(path)
    25 	return path:gsub("\\", "/"):gsub("//+", "/"):gsub("^~", os.getenv("HOME") or "~");
    26 	return path:gsub("\\", "/"):gsub("//+", "/"):gsub("^~", os_getenv("HOME") or "~");
    26 end
    27 end
    27 local encode, decode; do
    28 local encode, decode; do
    28 	local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end });
    29 	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
    30 	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
    31 	encode = function (s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end