r453 - in trunk: . examples/duke3d scripts

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Mon Jan 21 04:42:06 EST 2008


Author: icculus
Date: 2008-01-21 04:41:56 -0500 (Mon, 21 Jan 2008)
New Revision: 453

Modified:
   trunk/examples/duke3d/make.sh
   trunk/lua_glue.c
   trunk/scripts/localization.lua
   trunk/scripts/mojosetup_init.lua
   trunk/scripts/mojosetup_mainline.lua
Log:
A ton more fixes.


Modified: trunk/examples/duke3d/make.sh
===================================================================
--- trunk/examples/duke3d/make.sh	2008-01-21 07:48:07 UTC (rev 452)
+++ trunk/examples/duke3d/make.sh	2008-01-21 09:41:56 UTC (rev 453)
@@ -49,6 +49,7 @@
 mkdir image/meta
 
 # Build MojoSetup binaries from scratch.
+# YOU ALWAYS NEED THE LUA PARSER IF YOU WANT UNINSTALL SUPPORT!
 cd ../..
 rm -rf `svn propget svn:ignore .`
 cmake \
@@ -61,7 +62,7 @@
     -DMOJOSETUP_LUALIB_MATH=FALSE \
     -DMOJOSETUP_LUALIB_OS=FALSE \
     -DMOJOSETUP_LUALIB_PACKAGE=FALSE \
-    -DMOJOSETUP_LUA_PARSER=$TRUEIFDEBUG \
+    -DMOJOSETUP_LUA_PARSER=TRUE \
     -DMOJOSETUP_IMAGE_BMP=TRUE \
     -DMOJOSETUP_IMAGE_JPG=FALSE \
     -DMOJOSETUP_IMAGE_PNG=FALSE \

Modified: trunk/lua_glue.c
===================================================================
--- trunk/lua_glue.c	2008-01-21 07:48:07 UTC (rev 452)
+++ trunk/lua_glue.c	2008-01-21 09:41:56 UTC (rev 453)
@@ -703,6 +703,16 @@
 } // luahook_wildcardmatch
 
 
+// Do a regular C strcmp(), don't let the locale get in the way like it does
+//  in Lua's string comparison operators.
+static int luahook_strcmp(lua_State *L)
+{
+    const char *a = luaL_checkstring(L, 1);
+    const char *b = luaL_checkstring(L, 2);
+    return retvalNumber(L, strcmp(a, b));
+} // luahook_strcmp
+
+
 static int luahook_findmedia(lua_State *L)
 {
     // Let user specify overrides of directories to act as drives.
@@ -1587,6 +1597,7 @@
         set_cfunc(luaState, luahook_date, "date");
         set_cfunc(luaState, luahook_isvalidperms, "isvalidperms");
         set_cfunc(luaState, luahook_checksum, "checksum");
+        set_cfunc(luaState, luahook_strcmp, "strcmp");
 
         // Set some information strings...
         lua_newtable(luaState);

Modified: trunk/scripts/localization.lua
===================================================================
--- trunk/scripts/localization.lua	2008-01-21 07:48:07 UTC (rev 452)
+++ trunk/scripts/localization.lua	2008-01-21 09:41:56 UTC (rev 453)
@@ -943,6 +943,11 @@
     --  file for some reason. '%0' is the manifest's package name.
     ["Couldn't load manifest file for '%0'"] = {
     };
+
+    -- This error is shown when the user prompted the app to read a filename
+    --  (%0) that doesn't exist.
+    ["File %0 not found"] = {
+    };
 };
 
 -- end of localization.lua ...

Modified: trunk/scripts/mojosetup_init.lua
===================================================================
--- trunk/scripts/mojosetup_init.lua	2008-01-21 07:48:07 UTC (rev 452)
+++ trunk/scripts/mojosetup_init.lua	2008-01-21 09:41:56 UTC (rev 453)
@@ -238,6 +238,11 @@
 -- Actual schema elements are below...
 
 function Setup.Package(tab)
+    -- !!! FIXME: allow_uninstall
+    -- !!! FIXME: write_manifest
+    -- !!! FIXME: allow_uninstall must check write_manifest, write_manifest
+    -- !!! FIXME:  must check for Lua parser support...or something like that.
+
     tab = sanitize("Package", tab,
     {
         { "id", nil, mustExist, mustBeString, cantBeEmpty },

Modified: trunk/scripts/mojosetup_mainline.lua
===================================================================
--- trunk/scripts/mojosetup_mainline.lua	2008-01-21 07:48:07 UTC (rev 452)
+++ trunk/scripts/mojosetup_mainline.lua	2008-01-21 09:41:56 UTC (rev 453)
@@ -22,14 +22,14 @@
 end
 
 
-local function manifest_rechecksum(man, fname, _key)
+local function manifest_resync(man, fname, _key)
     if fname == nil then return end
 
     local fullpath = fname
 
     local destlen = string.len(MojoSetup.destination)
     if string.sub(fname, 0, destlen) == MojoSetup.destination then
-        fname = string.sub(path, destlen+2)  -- make it relative.
+        fname = string.sub(fname, destlen+2)  -- make it relative.
     end
 
     if man[fname] == nil then
@@ -64,6 +64,14 @@
 end
 
 
+-- !!! FIXME: I need to go back from managing everything installed through
+-- !!! FIXME:  the manifest to a separate table of "things written to disk
+-- !!! FIXME:  on just this run" ... the existing manifest code can stay as-is,
+-- !!! FIXME:  rollbacks should be done exclusively from that other table.
+-- !!! FIXME: Right now we're relying on dumb stuff like sorting the filenames
+-- !!! FIXME:  to get a safe deletion order on revert, but we should just
+-- !!! FIXME:  keep a chronological array instead.
+
 local function manifest_add(man, fname, _key, ftype, mode, sums, lndest)
     if (fname ~= nil) and (_key ~= nil) then
         local destlen = string.len(MojoSetup.destination)
@@ -176,14 +184,18 @@
 
 
 -- get a linear array of filenames in the manifest.
-local function flatten_manifest(man)
+local function flatten_manifest(man, postprocess)
     local files = {}
+    if postprocess == nil then
+        postprocess = function(x) return x end
+    end
     if man ~= nil then
         for fname,items in pairs(man) do
-            files[#files+1] = fname
+            files[#files+1] = postprocess(fname)
         end
     end
 
+    table.sort(files, function(a,b) return MojoSetup.strcmp(a,b) < 0 end)
     return files
 end
 
@@ -196,9 +208,16 @@
 
     MojoSetup.loginfo("Cleaning up half-finished installation...")
 
+    local function processor(fname)
+        if fname == "" then
+            return MojoSetup.destination
+        end
+        return MojoSetup.destination .. "/" .. fname
+    end
+
     -- !!! FIXME: callbacks here.
     delete_files(MojoSetup.downloads)
-    delete_files(flatten_manifest(MojoSetup.manifest))
+    delete_files(flatten_manifest(MojoSetup.manifest, processor))
     do_rollbacks()
     delete_scratchdirs()
 end
@@ -415,6 +434,9 @@
 -- !!! FIXME: we should probably pump the GUI queue here, in case there are
 -- !!! FIXME:  thousands of dirs in a row or something.
 local function install_directory(dest, perms, manifestkey)
+    -- Chop any '/' chars from the end of the string...
+    dest = string.gsub(dest, "/+$", "")
+
     if not MojoSetup.platform.mkdir(dest, perms) then
         MojoSetup.logerror("Failed to create dir '" .. dest .. "'")
         MojoSetup.fatal(_("Directory creation failed"))
@@ -477,7 +499,7 @@
             if allowoverwrite then
                 local id = #MojoSetup.rollbacks + 1
                 local f = MojoSetup.rollbackdir .. "/" .. id
-                install_parent_dirs(f, nil)
+                install_parent_dirs(f, MojoSetup.metadatakey)
                 MojoSetup.rollbacks[id] = dest
                 if not MojoSetup.movefile(dest, f) then
                     MojoSetup.fatal(_("Couldn't backup file for rollback"))
@@ -664,10 +686,13 @@
 
 
 local function set_destination(dest)
+    -- Chop any '/' chars from the end of the string...
+    dest = string.gsub(dest, "/+$", "")
+
     MojoSetup.loginfo("Install dest: '" .. dest .. "'")
     MojoSetup.destination = dest
     MojoSetup.metadatadir = MojoSetup.destination .. "/.mojosetup"
-    MojoSetup.controldir = MojoSetup.metadatadir .. "/control"
+    MojoSetup.controldir = MojoSetup.metadatadir  -- .. "/control"
     MojoSetup.manifestdir = MojoSetup.metadatadir .. "/manifest"
     MojoSetup.scratchdir = MojoSetup.metadatadir .. "/tmp"
     MojoSetup.rollbackdir = MojoSetup.scratchdir .. "/rollbacks"
@@ -703,7 +728,7 @@
 
     local retval =
         '<?xml version="1.0" encoding="UTF-8"?>\n' ..
-        '<product name="' .. MojoSetup.install.id .. '" desc="' ..
+        '<product name="' .. package.id .. '" desc="' ..
         package.description .. '" xmlversion="1.6" root="' ..
         package.root .. '" ' .. updateurl .. '>\n' ..
         '\t<component name="Default" version="' .. package.version ..
@@ -808,7 +833,7 @@
 
 local function build_txt_manifest(package)
     local retval = ''
-    for path,item in pairs(package.manifest) do
+    for i,path in ipairs(flatten_manifest(package.manifest)) do
         retval = retval .. path .. "\n"
     end
     return retval
@@ -838,7 +863,7 @@
     end
 
     local perms = "0755"  -- !!! FIXME
-    install_parent_dirs(dst, key);
+    install_parent_dirs(dst, key)
     install_file_from_filesystem(dst, src, perms, desc, key, maxbytes)
 
     -- Okay, now we need all the support files.
@@ -953,6 +978,8 @@
     local stages = {}
 
     -- First stage: Make sure installer can run. Always fails or steps forward.
+    -- !!! FIXME: you can step back onto this...need a way to run some stages
+    -- !!! FIXME:  only once...
     if install.precheck ~= nil then
         stages[#stages+1] = function ()
             run_config_defined_hook(install.precheck, install)
@@ -1104,6 +1131,11 @@
     --  This is not a GUI stage, it just needs to run between them.
     --  This gets a little hairy.
     stages[#stages+1] = function(thisstage, maxstage)
+        -- Make sure we install the destination dir, so it's in the manifest.
+        if not MojoSetup.platform.exists(MojoSetup.destination) then
+            install_directory(MojoSetup.destination, nil, MojoSetup.metadatakey)
+        end
+
         local function process_file(option, file)
             -- !!! FIXME: what happens if a file shows up in multiple options?
             local src = file.source
@@ -1193,7 +1225,7 @@
             local id = 0
             for file,option in pairs(MojoSetup.files.downloads) do
                 local f = MojoSetup.downloaddir .. "/" .. id
-                install_parent_dirs(f, nil)
+                install_parent_dirs(f, MojoSetup.metadatakey)
                 id = id + 1
 
                 -- Upvalued so we don't look these up each time...
@@ -1421,7 +1453,9 @@
 
 
 local function manifest_management()
-    local pkg = MojoSetup.info.argv[2]
+    MojoSetup.loginfo("Manifest management starting")
+
+    local pkg = MojoSetup.info.argv[3]
     if pkg == nil then
         badcmdline()
     end
@@ -1444,7 +1478,7 @@
     --  someone could have moved the installation's folder elsewhere. We'll
     --  keep it up to date for loki_update or whatever to use, though.
 
-    local i = 2
+    local i = 4
     while MojoSetup.info.argv[i] ~= nil do
         local cmd = MojoSetup.info.argv[i]
         i = i + 1
@@ -1454,14 +1488,19 @@
             i = i + 1
             local fname = MojoSetup.info.argv[i]
             i = i + 1
-            if (opt == nil) or (fname == nil) then
+            if (key == nil) or (fname == nil) then
                 badcmdline()
             end
 
             MojoSetup.loginfo("Add '" ..fname.. "', '" ..key.. "' to manifest")
-            manifest_add(package.manifest, fname, key, nil, nil, nil, nil)
-            manifest_resync(package.manifest, fname)
+            fname = MojoSetup.destination .. "/" .. fname
+            if not MojoSetup.platform.exists(fname) then
+                MojoSetup.fatal(MojoSetup.format(_("File %0 not found"), fname))
+            end
 
+            manifest_add(MojoSetup.package.manifest, fname, key, nil, nil, nil, nil)
+            manifest_resync(MojoSetup.package.manifest, fname, key)
+
         elseif cmd == "delete" then
             local fname = MojoSetup.info.argv[i]
             i = i + 1
@@ -1469,7 +1508,8 @@
                 badcmdline()
             end
             MojoSetup.loginfo("Delete '" .. fname .. "' from manifest")
-            manifest_delete(package.manifest, fname)
+            fname = MojoSetup.destination .. "/" .. fname
+            manifest_delete(MojoSetup.package.manifest, fname)
 
         elseif cmd == "resync" then
             local fname = MojoSetup.info.argv[i]
@@ -1478,16 +1518,21 @@
                 badcmdline()
             end
             MojoSetup.loginfo("Resync '" .. fname .. "' in manifest")
-            manifest_resync(package.manifest, fname)
+            fname = MojoSetup.destination .. "/" .. fname
+            if not MojoSetup.platform..exists(fname) then
+                MojoSetup.fatal(MojoSetup.format(_("File %0 not found"), fname))
+            end
+            manifest_resync(MojoSetup.package.manifest, fname)
 
         else
+            MojoSetup.logerror("Unknown command '" .. cmd .. "'")
             badcmdline()
         end
     end
 
     -- !!! FIXME: duplication with install_manifests()
     local perms = "0644"  -- !!! FIXME
-    local basefname = MojoSetup.manifestdir .. "/" .. MojoSetup.install.id
+    local basefname = MojoSetup.manifestdir .. "/" .. MojoSetup.package.id
     local lua_fname = basefname .. ".lua"
     local xml_fname = basefname .. ".xml"
     local txt_fname = basefname .. ".txt"
@@ -1507,7 +1552,7 @@
 
 local function uninstaller()
     MojoSetup.fatal("Not implemented yet.")
-    local pkg = MojoSetup.info.argv[2]
+    local pkg = MojoSetup.info.argv[3]
     if pkg == nil then
         badcmdline()
     end
@@ -1520,10 +1565,12 @@
 local purpose = nil
 
 -- Have to check argv instead of using cmdline(), for precision's sake.
-local argv1 = MojoSetup.info.argv[1]
-if argv1 == "manifest" then
+-- Remember that unlike main()'s argv in C, Lua starts arrays at 1,
+--  so argv[2] would be argv[1] in C. Fun.
+local argv2 = MojoSetup.info.argv[2]
+if argv2 == "manifest" then
     purpose = manifest_management
-elseif argv1 == "uninstall" then
+elseif argv2 == "uninstall" then
     purpose = uninstaller
 else
     purpose = installer




More information about the mojosetup-commits mailing list