# HG changeset patch # User J. Ali Harlow # Date 1247003422 -3600 # Node ID d15a16347c778cede3bc1bbd29c09cdf3119fc92 # Parent c903635ae422d92ce94e3c507052b946383c856b Pass installation-count to scripts diff -r c903635ae422 -r d15a16347c77 librazor/lua.c --- a/librazor/lua.c Mon Jul 06 18:19:13 2009 +0100 +++ b/librazor/lua.c Tue Jul 07 22:50:22 2009 +0100 @@ -368,7 +368,7 @@ } int run_lua_script(const char *root, const char *name, const char *body, - ssize_t len) + ssize_t len, int arg1) { int i, n; lua_State *L; @@ -428,6 +428,20 @@ return -1; } + lua_newtable(L); + lua_pushvalue(L, LUA_GLOBALSINDEX); + lua_pushliteral(L, "arg"); + lua_pushvalue(L, -3); + lua_rawset(L, -3); + lua_pop(L, 1); + lua_pushliteral(L, ""); + lua_rawseti(L, -2, 1); + if (arg1 >= 0) { + lua_pushinteger(L, arg1); + lua_rawseti(L, -2, 2); + } + lua_pop(L, 1); + if (lua_pcall(L, 0, 0, 0)) { fprintf(stderr, "lua script failed: %s\n", lua_tostring(L, -1)); lua_pop(L, 1); diff -r c903635ae422 -r d15a16347c77 librazor/razor-internal.h --- a/librazor/razor-internal.h Mon Jul 06 18:19:13 2009 +0100 +++ b/librazor/razor-internal.h Tue Jul 07 22:50:22 2009 +0100 @@ -189,10 +189,10 @@ razor_merger_destroy(struct razor_merger *merger); int run_lua_script(const char *root, const char *name, const char *body, - ssize_t len); + ssize_t len, int arg1); int razor_run_script(const char *root, enum razor_property_flags script, - const char *program, const char *body); + const char *program, const char *body, int arg1); /* Utility functions */ diff -r c903635ae422 -r d15a16347c77 librazor/razor.c --- a/librazor/razor.c Mon Jul 06 18:19:13 2009 +0100 +++ b/librazor/razor.c Tue Jul 07 22:50:22 2009 +0100 @@ -472,12 +472,13 @@ * @set: a %razor_set * @package: a %razor_package * @root: the root into which the package is currently installed + * @install_count: the value to pass to uninstall scripts * * Removes an installed package. **/ RAZOR_EXPORT int razor_package_remove(struct razor_set *set, struct razor_package *package, - const char *root) + const char *root, int install_count) { struct razor_file_iterator *fi; struct razor_package_iterator *pi; @@ -504,7 +505,8 @@ RAZOR_DETAIL_LAST); environment_set(&env); - retval = razor_run_script(root, RAZOR_PROPERTY_PREUN, program, script); + retval = razor_run_script(root, RAZOR_PROPERTY_PREUN, program, script, + install_count); environment_unset(&env); if (retval) { @@ -539,7 +541,8 @@ RAZOR_DETAIL_LAST); environment_set(&env); - retval = razor_run_script(root, RAZOR_PROPERTY_POSTUN, program, script); + retval = razor_run_script(root, RAZOR_PROPERTY_POSTUN, program, script, + install_count); environment_unset(&env); environment_release(&env); diff -r c903635ae422 -r d15a16347c77 librazor/razor.h --- a/librazor/razor.h Mon Jul 06 18:19:13 2009 +0100 +++ b/librazor/razor.h Tue Jul 07 22:50:22 2009 +0100 @@ -110,7 +110,7 @@ struct razor_package *package, ...); int razor_package_remove(struct razor_set *set, struct razor_package *package, - const char *root); + const char *root, int install_count); /** @@ -291,7 +291,8 @@ void razor_rpm_get_details(struct razor_rpm *rpm, ...); void razor_rpm_set_relocations(struct razor_rpm *rpm, struct razor_relocations *relocations); -int razor_rpm_install(struct razor_rpm *rpm, const char *root); +int razor_rpm_install(struct razor_rpm *rpm, const char *root, + int install_count); int razor_rpm_close(struct razor_rpm *rpm); /** diff -r c903635ae422 -r d15a16347c77 librazor/rpm.c --- a/librazor/rpm.c Mon Jul 06 18:19:13 2009 +0100 +++ b/librazor/rpm.c Tue Jul 07 22:50:22 2009 +0100 @@ -874,7 +874,8 @@ } static int -run_script_lua(const char *root, unsigned int script_tag, const char *script) +run_script_lua(const char *root, unsigned int script_tag, const char *script, + int arg1) { int root_fd, retval; #if HAVE_LUA @@ -898,7 +899,8 @@ break; } root_fd = chroot_push(root); - retval = run_lua_script(root_fd < 0 ? root : NULL, name, script, -1); + retval = run_lua_script(root_fd < 0 ? root : NULL, name, script, -1, + arg1); chroot_pop(root_fd); #else /* HAVE_LUA */ fprintf(stderr, "lua not available to run script\n"); @@ -909,10 +911,12 @@ } static int -run_script_external(const char *root, const char *program, const char *script) +run_script_external(const char *root, const char *program, const char *script, + int arg1) { int root_fd, retval; FILE *fp; + char buf[32], *command; if (program == NULL) { #if MSWIN_API @@ -930,7 +934,14 @@ } root_fd = chroot_push(root); - fp = popen(program, "w"); + if (arg1 >= 0) { + sprintf(buf, "%d", arg1); + command = malloc(strlen(program) + strlen(buf) + 2); + sprintf(command, "%s %s", program, buf); + } else + command = strdup(program); + fp = popen(command, "w"); + free(command); if (!fp) { perror(program); @@ -950,12 +961,12 @@ static int run_script(struct installer *installer, - unsigned int program_tag, unsigned int script_tag) + unsigned int program_tag, unsigned int script_tag, int arg1) { int i, retval; struct razor_rpm *rpm = installer->rpm; const char *script = NULL, *program = NULL, *prefix; - char buf[32], *p; + char buf[32]; struct environment env; program = razor_rpm_get_indirect(rpm, program_tag, NULL); @@ -975,9 +986,11 @@ } if (program && strcmp(program, "") == 0) - retval = run_script_lua(installer->root, script_tag, script); + retval = run_script_lua(installer->root, script_tag, script, + arg1); else - retval = run_script_external(installer->root, program, script); + retval = run_script_external(installer->root, program, script, + arg1); if (rpm->relocations) { environment_unset(&env); @@ -989,7 +1002,7 @@ int razor_run_script(const char *root, enum razor_property_flags script, - const char *program, const char *body) + const char *program, const char *body, int arg1) { int retval; unsigned int script_tag; @@ -1020,10 +1033,10 @@ script_tag = 0; break; } - retval = run_script_lua(root, script_tag, body); + retval = run_script_lua(root, script_tag, body, arg1); } else - retval = run_script_external(root, program, body); + retval = run_script_external(root, program, body, arg1); return retval; } @@ -1101,7 +1114,7 @@ } RAZOR_EXPORT int -razor_rpm_install(struct razor_rpm *rpm, const char *root) +razor_rpm_install(struct razor_rpm *rpm, const char *root, int install_count) { struct installer installer; struct cpio_file_header *header; @@ -1130,7 +1143,7 @@ if (installer_init(&installer)) return -1; - run_script(&installer, RPMTAG_PREINPROG, RPMTAG_PREIN); + run_script(&installer, RPMTAG_PREINPROG, RPMTAG_PREIN, install_count); while (installer.stream.avail_in > 0) { installer.rest = sizeof *header; @@ -1167,7 +1180,7 @@ if (installer_finish(&installer)) return -1; - run_script(&installer, RPMTAG_POSTINPROG, RPMTAG_POSTIN); + run_script(&installer, RPMTAG_POSTINPROG, RPMTAG_POSTIN, install_count); return 0; } diff -r c903635ae422 -r d15a16347c77 librazor/test-lua.c --- a/librazor/test-lua.c Mon Jul 06 18:19:13 2009 +0100 +++ b/librazor/test-lua.c Tue Jul 07 22:50:22 2009 +0100 @@ -94,7 +94,7 @@ free(s); script = razor_file_get_contents(test_file, &len); - r = run_lua_script(root, test_file, script, len); + r = run_lua_script(root, test_file, script, len, -1); razor_file_free_contents(script, len); recursive_remove(root); diff -r c903635ae422 -r d15a16347c77 src/main.c --- a/src/main.c Mon Jul 06 18:19:13 2009 +0100 +++ b/src/main.c Tue Jul 07 22:50:22 2009 +0100 @@ -907,7 +907,7 @@ if (relocations) razor_rpm_set_relocations(rpm, relocations); razor_transaction_fixup_package(trans, package, rpm); - retval = razor_rpm_install(rpm, install_root); + retval = razor_rpm_install(rpm, install_root, 1); if (retval < 0) fprintf(stderr, "failed to install rpm %s\n", file); razor_rpm_close(rpm); @@ -932,7 +932,7 @@ relocations); else if (action == RAZOR_INSTALL_ACTION_REMOVE) retval = razor_package_remove(set, package, - install_root); + install_root, 0); } razor_install_iterator_destroy(ii); diff -r c903635ae422 -r d15a16347c77 test/zip.spec --- a/test/zip.spec Mon Jul 06 18:19:13 2009 +0100 +++ b/test/zip.spec Tue Jul 07 22:50:22 2009 +0100 @@ -33,7 +33,7 @@ if prefix==nil then prefix="/usr" end -if posix.stat(prefix.."/bin/zap")~=nil then +if arg[2]==1 and posix.stat(prefix.."/bin/zap")~=nil then mkdir_missing(prefix.."/var") mkdir_missing(prefix.."/var/lib") posix.mkdir(prefix.."/var/lib/zip") @@ -47,7 +47,7 @@ if prefix==nil then prefix="/usr" end -if posix.stat(prefix.."/bin/zap")~=nil then +if arg[2]==0 and posix.stat(prefix.."/bin/zap")~=nil then os.remove(prefix.."/var/lib/zip/data.zap") os.remove(prefix.."/var/lib/zip") end diff -r c903635ae422 -r d15a16347c77 test/zsh.spec --- a/test/zsh.spec Mon Jul 06 18:19:13 2009 +0100 +++ b/test/zsh.spec Tue Jul 07 22:50:22 2009 +0100 @@ -35,7 +35,7 @@ if prefix==nil then prefix="/usr" end -if posix.stat(prefix.."/bin/zip")~=nil then +if arg[2]==1 and posix.stat(prefix.."/bin/zip")~=nil then mkdir_missing(prefix.."/var") mkdir_missing(prefix.."/var/lib") posix.mkdir(prefix.."/var/lib/zsh") @@ -49,7 +49,7 @@ if prefix==nil then prefix="/usr" end -if posix.stat(prefix.."/bin/zip")~=nil then +if arg[2]==0 and posix.stat(prefix.."/bin/zip")~=nil then os.remove(prefix.."/var/lib/zsh/data.zip") os.remove(prefix.."/var/lib/zsh") end