migrate.lua 640 B

1234567891011121314151617181920212223242526
  1. -- migrate from mail.db to player-file-based mailbox
  2. mail.migrate = function()
  3. -- create directory, just in case
  4. minetest.mkdir(mail.maildir)
  5. local file = io.open(minetest.get_worldpath().."/mail.db", "r")
  6. if file then
  7. print("[mail] migrating to new per-player storage")
  8. local data = file:read("*a")
  9. local oldmails = minetest.deserialize(data)
  10. file:close()
  11. for name, oldmessages in pairs(oldmails) do
  12. mail.setMessages(name, oldmessages)
  13. end
  14. -- rename file
  15. print("[mail] migration done, renaming old mail.db")
  16. os.rename(minetest.get_worldpath().."/mail.db", minetest.get_worldpath().."/mail.db.old")
  17. end
  18. end