local ostree = require "ostree"; -- TODO: make this an option local repo_url = "https://dl.flathub.org/repo"; return function (name, out) local repo = ostree.from_http(repo_url); local ref = repo:read_ref(name); local commit = repo:read_commit(ref); local function dump_file(path, file) print("Dumping " .. path .. "..."); local file_obj = repo:read_file(file); if file_obj.type == "file" then local f = assert(io.open(out .. "/" .. path, "w")); for seg in file_obj.get_content() do assert(f:write(seg)); end f:close(); else os.execute(("ln -s %q %q"):format(file_obj.target, out .. "/" .. path)); end end local function dump_dir(path, dir) print("Dumping " .. path .. "..."); os.execute(("mkdir %q"):format(out .. "/" .. path)); local dir_obj = repo:read_dir(dir); for subname, subdir in pairs(dir_obj.dirs) do dump_dir(path .. "/" .. subname, subdir); end for subname, subfile in pairs(dir_obj.files) do dump_file(path .. "/" .. subname, subfile); end end dump_dir("/", commit.root); end