--- mojosetup-original/scripts/mojosetup_mainline.lua 2009-05-27 14:38:51.000000000 +0200 +++ mojosetup-modded/scripts/mojosetup_mainline.lua 2009-06-01 05:11:03.000000000 +0200 @@ -438,6 +438,36 @@ local function install_file_from_string( end +local function install_file_from_stringtable(dest, stringtable, perms, desc, manifestkey) + local fn = function(callback) + local file = io.open(dest, "a+") + local start = MojoSetup.ticks() + local done = 0 + local total = 0 + if file == nil then + return false + else + -- for key, value in pairs(stringtable) do + -- total = total + string.len(value) + -- end + for key, value in pairs(stringtable) do + file:write(value) + -- done = done + string.len(value) --this works, but slows the whole thing down + -- callback(MojoSetup.ticks() - start, string.len(value), done, total) + end + end + file:close() + MojoSetup.platform.chmod(dest, perms) + return true -- !!! FIXME: what's about some checking? + end + if perms == nil then + perms = "0644" -- !!! FIXME: should there be anything better here? + end + return install_file(dest, perms, fn, desc, manifestkey) + +end + + local function install_file_from_filesystem(dest, src, perms, desc, manifestkey, maxbytes) local fn = function(callback) return MojoSetup.copyfile(src, dest, perms, maxbytes, callback) @@ -746,12 +776,13 @@ end -- lua manifest, for example (but loki_uninstall can use the xml one, -- so if you want, you can just drop in MojoSetup to replace loki_setup and -- use the Loki tools for everything else. + local function build_xml_manifest(package) local updateurl = package.update_url if updateurl ~= nil then updateurl = 'update_url="' .. updateurl .. '"' else - updateurl = '' + updateurl = '' end local retval = @@ -820,6 +851,80 @@ local function build_xml_manifest(packag return retval end +local function build_xml_manifest_as_stringtable(package) + stringtable = {} + local updateurl = package.update_url + if updateurl ~= nil then + updateurl = 'update_url="' .. updateurl .. '"' + else + updateurl = '' + end + + local head = + '\n' .. + '\n' .. + '\t\n' + + -- Need to group these by options. + local grouped = {} + for fname,entity in pairs(package.manifest) do + local key = entity.key + if grouped[key] == nil then + grouped[key] = {} + end + entity.path = fname + local list = grouped[key] + list[#list+1] = entity + end + stringtable[#stringtable+1] = head + for desc,items in pairs(grouped) do + stringtable[#stringtable+1] = '\t\t\n' + end + + stringtable[#stringtable+1] = '\t\n' + stringtable[#stringtable+1] = '\n\n' + return stringtable +end + local function serialize(obj) local function _serialize(obj, indent) @@ -840,7 +945,7 @@ local function serialize(obj) local key = k if type(key) == "number" then key = '[' .. key .. ']' - elseif not string.match(key, "^[_a-zA-Z][_a-zA-Z0-9]*$") then + elseif not string.match(key, "^[_a-zA-Z][_a-zA-Z0-9]*$") then key = '[' .. string.format("%q", key) .. ']' end retval = retval .. tab .. key .. " = " .. @@ -859,8 +964,52 @@ local function serialize(obj) end + + local function build_lua_manifest(package) - return 'MojoSetup.package = ' .. serialize(package) .. "\n\n" + return 'MojoSetup.package = ' .. serialize(package) .. "\n\n" +end + + +local function build_lua_manifest_as_stringtable(package) + + local function create_stringtable(sourcetable, indent, newtable) + local objtype = type(sourcetable) + if objtype == "nil" then + MojoSetup.logerror("serialize_to_lua_stringtable does not expect a nil value") + elseif (objtype == "number") or (objtype == "boolean") then + newtable[#newtable+1] = tostring(sourcetable) + elseif objtype == "string" then + newtable[#newtable+1] = string.format("%q", sourcetable) + elseif objtype == "function" then + newtable[#newtable+1] = "loadstring(" .. string.format("%q", string.dump(sourcetable)) .. ")" + elseif objtype == "table" then + newtable[#newtable+1] = "{\n" + local tab = string.rep("\t", indent) + for k,v in pairs(sourcetable) do + local key = k + if type(key) == "number" then + key = '[' .. key .. ']' + elseif not string.match(key, "^[_a-zA-Z][_a-zA-Z0-9]*$") then + key = '[' .. string.format("%q", key) .. ']' + end + newtable[#newtable+1] = tab .. key .. " = " + create_stringtable(v, indent+1, newtable) + newtable[#newtable+1] = ",\n" + end + newtable[#newtable+1] = string.rep("\t", indent-1) .. "}" + else + MojoSetup.logerror("unexpected object to serialize (" .. + objtype .. "): '" .. tostring(sourcetable) .. "'") + MojoSetup.fatal(_("BUG: Unhandled data type")) + end + return newtable + end + retval = {} + retval[#retval+1] = "MojoSetup.package = " + create_stringtable(package, 1, retval) + retval[#retval+1] = "\n\n" + return retval end @@ -873,6 +1022,15 @@ local function build_txt_manifest(packag end +local function build_txt_manifest_as_stringtable(package) + local retval = {} + for i,path in ipairs(flatten_manifest(package.manifest)) do + retval[#retval+1] = path .. "\n" + end + return retval +end + + local function install_control_app(desc, key) local dst, src @@ -1009,12 +1167,16 @@ local function install_manifests(desc, k -- now build these things... install_parent_dirs(lua_fname, key) - install_file_from_string(lua_fname, build_lua_manifest(package), perms, desc, nil) - install_file_from_string(xml_fname, build_xml_manifest(package), perms, desc, nil) - install_file_from_string(txt_fname, build_txt_manifest(package), perms, desc, nil) -end - +-- install_file_from_string(lua_fname, build_lua_manifest(package), perms, desc, nil) +-- install_file_from_string(xml_fname, build_xml_manifest(package), perms, desc, nil) +-- install_file_from_string(txt_fname, build_txt_manifest(package), perms, desc, nil) + + install_file_from_stringtable(lua_fname, build_lua_manifest_as_stringtable(package), perms, desc, nil) + install_file_from_stringtable(xml_fname, build_xml_manifest_as_stringtable(package), perms, desc, nil) + install_file_from_stringtable(txt_fname, build_txt_manifest_as_stringtable(package), perms, desc, nil) +end + local function freedesktop_menuitem_filename(pkg, idx) -- only for Unix. local vendor = string.gsub(pkg.vendor, "%.", "_") local fname = vendor .. "-" .. pkg.id .. "_" .. idx .. ".desktop" @@ -1923,9 +2085,13 @@ local function manifest_management() -- !!! FIXME: rollback! delete_files({lua_fname, xml_fname, txt_fname}, nil, false) - MojoSetup.stringtofile(build_lua_manifest(package), lua_fname, perms, nil, nil) - MojoSetup.stringtofile(build_xml_manifest(package), xml_fname, perms, nil, nil) - MojoSetup.stringtofile(build_txt_manifest(package), txt_fname, perms, nil, nil) + --MojoSetup.stringtofile(build_lua_manifest(package), lua_fname, perms, nil, nil) + --MojoSetup.stringtofile(build_xml_manifest(package), xml_fname, perms, nil, nil) + --MojoSetup.stringtofile(build_txt_manifest(package), txt_fname, perms, nil, nil) + + install_file_from_stringtable(lua_fname, build_lua_manifest_as_stringtable(package), perms, nil) + install_file_from_stringtable(xml_fname, build_xml_manifest_as_stringtable(package), perms, nil) + install_file_from_stringtable(txt_fname, build_txt_manifest_as_stringtable(package), perms, nil) MojoSetup.loginfo("manifests rebuilt!") end