Comparison

tools/migration/migrator/prosody_files.lua @ 7881:4e3067272fae

tools/migration/migrator/*: Remove use of module()
author Kim Alvefur <zash@zash.se>
date Thu, 02 Feb 2017 20:49:09 +0100
parent 5974:9ce0d246c851
comparison
equal deleted inserted replaced
7880:1d998891c967 7881:4e3067272fae
16 local error = error; 16 local error = error;
17 17
18 prosody = {}; 18 prosody = {};
19 local dm = require "util.datamanager" 19 local dm = require "util.datamanager"
20 20
21 module "prosody_files"
22 21
23 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
24 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
25 local function clean_path(path) 24 local function clean_path(path)
26 return path:gsub("\\", "/"):gsub("//+", "/"):gsub("^~", os_getenv("HOME") or "~"); 25 return path:gsub("\\", "/"):gsub("//+", "/"):gsub("^~", os_getenv("HOME") or "~");
86 store.user = nil; store.host = nil; store.store = nil; 85 store.user = nil; store.host = nil; store.store = nil;
87 end 86 end
88 return userdata; 87 return userdata;
89 end 88 end
90 89
91 function reader(input) 90 local function reader(input)
92 local path = clean_path(assert(input.path, "no input.path specified")); 91 local path = clean_path(assert(input.path, "no input.path specified"));
93 assert(is_dir(path), "input.path is not a directory"); 92 assert(is_dir(path), "input.path is not a directory");
94 local iter = coroutine.wrap(function()handle_root_dir(path);end); 93 local iter = coroutine.wrap(function()handle_root_dir(path);end);
95 -- get per-user stores, sorted 94 -- get per-user stores, sorted
96 local iter = mtools.sorted { 95 local iter = mtools.sorted {
125 local x = iter(); 124 local x = iter();
126 return x and decode_user(x); 125 return x and decode_user(x);
127 end 126 end
128 end 127 end
129 128
130 function writer(output) 129 local function writer(output)
131 local path = clean_path(assert(output.path, "no output.path specified")); 130 local path = clean_path(assert(output.path, "no output.path specified"));
132 assert(is_dir(path), "output.path is not a directory"); 131 assert(is_dir(path), "output.path is not a directory");
133 return function(item) 132 return function(item)
134 if not item then return; end -- end of input 133 if not item then return; end -- end of input
135 dm.set_data_path(path); 134 dm.set_data_path(path);
137 assert(dm.store(item.user, item.host, store, data)); 136 assert(dm.store(item.user, item.host, store, data));
138 end 137 end
139 end 138 end
140 end 139 end
141 140
142 return _M; 141 return {
142 reader = reader;
143 writer = writer;
144 }