Software /
code /
prosody
Annotate
tools/migration/migrator/prosody_files.lua @ 8666:57780ba1938f
util.startup: Move original_logging_config to a local variable
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 22 Mar 2018 21:46:55 +0000 |
parent | 7881:4e3067272fae |
rev | line source |
---|---|
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
1 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
2 local print = print; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
3 local assert = assert; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
4 local setmetatable = setmetatable; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
5 local tonumber = tonumber; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
6 local char = string.char; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
7 local coroutine = coroutine; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
8 local lfs = require "lfs"; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
9 local loadfile = loadfile; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
10 local pcall = pcall; |
4216
ff80a8471e86
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
Matthew Wild <mwild1@gmail.com>
parents:
4166
diff
changeset
|
11 local mtools = require "migrator.mtools"; |
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
12 local next = next; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
13 local pairs = pairs; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
14 local json = require "util.json"; |
4241
49b9e73e31ef
tools/migration/migrator/prosody_files.lua: Fix for previous commit
Matthew Wild <mwild1@gmail.com>
parents:
4239
diff
changeset
|
15 local os_getenv = os.getenv; |
5974
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
16 local error = error; |
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
17 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
18 prosody = {}; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
19 local dm = require "util.datamanager" |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
20 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
21 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
22 local function is_dir(path) return lfs.attributes(path, "mode") == "directory"; end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
23 local function is_file(path) return lfs.attributes(path, "mode") == "file"; end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
24 local function clean_path(path) |
4241
49b9e73e31ef
tools/migration/migrator/prosody_files.lua: Fix for previous commit
Matthew Wild <mwild1@gmail.com>
parents:
4239
diff
changeset
|
25 return path:gsub("\\", "/"):gsub("//+", "/"):gsub("^~", os_getenv("HOME") or "~"); |
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
26 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
27 local encode, decode; do |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
28 local urlcodes = setmetatable({}, { __index = function (t, k) t[k] = char(tonumber("0x"..k)); return t[k]; end }); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
29 decode = function (s) return s and (s:gsub("+", " "):gsub("%%([a-fA-F0-9][a-fA-F0-9])", urlcodes)); end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
30 encode = function (s) return s and (s:gsub("%W", function (c) return format("%%%02x", c:byte()); end)); end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
31 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
32 local function decode_dir(x) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
33 if x:gsub("%%%x%x", ""):gsub("[a-zA-Z0-9]", "") == "" then |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
34 return decode(x); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
35 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
36 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
37 local function decode_file(x) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
38 if x:match(".%.dat$") and x:gsub("%.dat$", ""):gsub("%%%x%x", ""):gsub("[a-zA-Z0-9]", "") == "" then |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
39 return decode(x:gsub("%.dat$", "")); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
40 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
41 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
42 local function prosody_dir(path, ondir, onfile, ...) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
43 for x in lfs.dir(path) do |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
44 local xpath = path.."/"..x; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
45 if decode_dir(x) and is_dir(xpath) then |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
46 ondir(xpath, x, ...); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
47 elseif decode_file(x) and is_file(xpath) then |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
48 onfile(xpath, x, ...); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
49 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
50 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
51 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
52 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
53 local function handle_root_file(path, name) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
54 --print("root file: ", decode_file(name)) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
55 coroutine.yield { user = nil, host = nil, store = decode_file(name) }; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
56 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
57 local function handle_host_file(path, name, host) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
58 --print("host file: ", decode_dir(host).."/"..decode_file(name)) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
59 coroutine.yield { user = nil, host = decode_dir(host), store = decode_file(name) }; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
60 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
61 local function handle_store_file(path, name, store, host) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
62 --print("store file: ", decode_file(name).."@"..decode_dir(host).."/"..decode_dir(store)) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
63 coroutine.yield { user = decode_file(name), host = decode_dir(host), store = decode_dir(store) }; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
64 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
65 local function handle_host_store(path, name, host) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
66 prosody_dir(path, function() end, handle_store_file, name, host); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
67 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
68 local function handle_host_dir(path, name) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
69 prosody_dir(path, handle_host_store, handle_host_file, name); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
70 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
71 local function handle_root_dir(path) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
72 prosody_dir(path, handle_host_dir, handle_root_file); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
73 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
74 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
75 local function decode_user(item) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
76 local userdata = { |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
77 user = item[1].user; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
78 host = item[1].host; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
79 stores = {}; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
80 }; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
81 for i=1,#item do -- loop over stores |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
82 local result = {}; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
83 local store = item[i]; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
84 userdata.stores[store.store] = store.data; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
85 store.user = nil; store.host = nil; store.store = nil; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
86 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
87 return userdata; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
88 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
89 |
7881
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5974
diff
changeset
|
90 local function reader(input) |
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
91 local path = clean_path(assert(input.path, "no input.path specified")); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
92 assert(is_dir(path), "input.path is not a directory"); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
93 local iter = coroutine.wrap(function()handle_root_dir(path);end); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
94 -- get per-user stores, sorted |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
95 local iter = mtools.sorted { |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
96 reader = function() |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
97 local x = iter(); |
5974
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
98 while x do |
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
99 dm.set_data_path(path); |
4293
419354c47c28
migrator/prosody_files: Don't choke on empty data stores for a user (thanks @eoranged)
Matthew Wild <mwild1@gmail.com>
parents:
4241
diff
changeset
|
100 local err; |
419354c47c28
migrator/prosody_files: Don't choke on empty data stores for a user (thanks @eoranged)
Matthew Wild <mwild1@gmail.com>
parents:
4241
diff
changeset
|
101 x.data, err = dm.load(x.user, x.host, x.store); |
419354c47c28
migrator/prosody_files: Don't choke on empty data stores for a user (thanks @eoranged)
Matthew Wild <mwild1@gmail.com>
parents:
4241
diff
changeset
|
102 if x.data == nil and err then |
5974
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
103 local p = dm.getpath(x.user, x.host, x.store); |
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
104 print(("Error loading data at path %s for %s@%s (%s store): %s") |
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
105 :format(p, x.user or "<nil>", x.host or "<nil>", x.store or "<nil>", err or "<nil>")); |
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
106 else |
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
107 return x; |
4293
419354c47c28
migrator/prosody_files: Don't choke on empty data stores for a user (thanks @eoranged)
Matthew Wild <mwild1@gmail.com>
parents:
4241
diff
changeset
|
108 end |
5974
9ce0d246c851
tools/migration/migrator/prosody_files: Fix undefined global access of ‘error’, print the actual error message and correct file path in the error message when we fail to load a file, skip broken files instead of failing migration.
Waqas Hussain <waqas20@gmail.com>
parents:
5021
diff
changeset
|
109 x = iter(); |
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
110 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
111 end; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
112 sorter = function(a, b) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
113 local a_host, a_user, a_store = a.host or "", a.user or "", a.store or ""; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
114 local b_host, b_user, b_store = b.host or "", b.user or "", b.store or ""; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
115 return a_host > b_host or (a_host==b_host and a_user > b_user) or (a_host==b_host and a_user==b_user and a_store > b_store); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
116 end; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
117 }; |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
118 -- merge stores to get users |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
119 iter = mtools.merged(iter, function(a, b) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
120 return (a.host == b.host and a.user == b.user); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
121 end); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
122 |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
123 return function() |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
124 local x = iter(); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
125 return x and decode_user(x); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
126 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
127 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
128 |
7881
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5974
diff
changeset
|
129 local function writer(output) |
4166
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
130 local path = clean_path(assert(output.path, "no output.path specified")); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
131 assert(is_dir(path), "output.path is not a directory"); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
132 return function(item) |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
133 if not item then return; end -- end of input |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
134 dm.set_data_path(path); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
135 for store, data in pairs(item.stores) do |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
136 assert(dm.store(item.user, item.host, store, data)); |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
137 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
138 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
139 end |
3ac90743039b
tools/migration/*.lua: Convert to unix line endings
Matthew Wild <mwild1@gmail.com>
parents:
4162
diff
changeset
|
140 |
7881
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5974
diff
changeset
|
141 return { |
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5974
diff
changeset
|
142 reader = reader; |
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5974
diff
changeset
|
143 writer = writer; |
4e3067272fae
tools/migration/migrator/*: Remove use of module()
Kim Alvefur <zash@zash.se>
parents:
5974
diff
changeset
|
144 } |