Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Die @exec/@unexec
Baptiste Daroussin committed 14 years ago
commit 4cab8e030fc38c0f1c51c8d1cb5f23f14c274249
parent 9eeb4d0
4 files changed +46 -20
modified libpkg/pkg.c
@@ -569,9 +569,11 @@ pkg_addscript(struct pkg *pkg, const char *path)
}

int
-
pkg_addexec(struct pkg *pkg, const char *cmd, pkg_exec_t type)
+
pkg_appendscript(struct pkg *pkg, const char *cmd, pkg_script_t type)
{
-
	struct pkg_exec *exec;
+
	int i;
+
	struct pkg_script **scripts;
+
	struct pkg_script *p_i_script = NULL;

	if (pkg == NULL)
		return (ERROR_BAD_ARG("pkg"));
@@ -579,13 +581,28 @@ pkg_addexec(struct pkg *pkg, const char *cmd, pkg_exec_t type)
	if (cmd == NULL || cmd[0] == '\0')
		return (ERROR_BAD_ARG("cmd"));

-
	pkg_exec_new(&exec);
+
	if ((scripts = pkg_scripts(pkg)) != NULL) {
+
		for (i = 0; scripts[i] != NULL; i++) {
+
			if (pkg_script_type(scripts[i]) == type) {
+
				p_i_script = scripts[i];
+
				break;
+
			}
+
		}
+
	}
+

+
	if (p_i_script != NULL) {
+
		sbuf_cat(p_i_script->data, cmd);
+
		sbuf_done(p_i_script->data);
+
		return (EPKG_OK);
+
	}

-
	sbuf_set(&exec->cmd, cmd);
-
	exec->type = type;
+
	pkg_script_new(&p_i_script);
+
	sbuf_set(&p_i_script->data, cmd);

-
	array_init(&pkg->exec, 5);
-
	array_append(&pkg->exec, exec);
+
	p_i_script->type = type;
+

+
	array_init(&pkg->scripts, 6);
+
	array_append(&pkg->scripts, p_i_script);

	return (EPKG_OK);
}
modified libpkg/pkg.h
@@ -314,11 +314,6 @@ int pkg_addfile(struct pkg *pkg, const char *path, const char *sha256);
 */
int pkg_addconflict(struct pkg *pkg, const char *glob);

-
/**
-
 * Allocate a new struct pkg_exec and add it to the execs of pkg.
-
 * @return An error code.
-
 */
-
int pkg_addexec(struct pkg *pkg, const char *cmd, pkg_exec_t type);

/**
 * Allocate a new struct pkg_script and add it to the scripts of pkg.
@@ -326,6 +321,7 @@ int pkg_addexec(struct pkg *pkg, const char *cmd, pkg_exec_t type);
 @ @return An error code.
 */
int pkg_addscript(struct pkg *pkg, const char *path);
+
int pkg_appendscript(struct pkg *pkg, const char *cmd, pkg_script_t type);

/**
 * Allocate a new struct pkg_option and add it to the options of pkg.
modified libpkg/pkg_ports.c
@@ -25,6 +25,8 @@ ports_parse_plist(struct pkg *pkg, char *plist)
	int ret = EPKG_OK;
	off_t sz = 0;
	int64_t flatsize = 0;
+
	struct sbuf *exec_scripts = sbuf_new_auto();
+
	struct sbuf *unexec_scripts = sbuf_new_auto();

	buf = NULL;
	p = NULL;
@@ -71,9 +73,9 @@ ports_parse_plist(struct pkg *pkg, char *plist)
					continue;

				if (plist_p[1] == 'u')
-
					pkg_addexec(pkg, cmd, PKG_UNEXEC);
+
					sbuf_printf(unexec_scripts, "%s\n", cmd);
				else
-
					pkg_addexec(pkg, cmd, PKG_EXEC);
+
					sbuf_printf(exec_scripts, "%s\n", cmd);

				free(cmd);

@@ -130,6 +132,17 @@ ports_parse_plist(struct pkg *pkg, char *plist)
	}

	pkg_setflatsize(pkg, flatsize);
+
	if (sbuf_len(exec_scripts) > 0) {
+
		sbuf_done(exec_scripts);
+
		pkg_appendscript(pkg, sbuf_data(exec_scripts), PKG_SCRIPT_POST_INSTALL);
+
	}
+
	if (sbuf_len(unexec_scripts) > 0) {
+
		sbuf_done(unexec_scripts);
+
		pkg_appendscript(pkg, sbuf_data(unexec_scripts), PKG_SCRIPT_POST_DEINSTALL);
+
	}
+

+
	sbuf_delete(exec_scripts);
+
	sbuf_delete(unexec_scripts);

	free(plist_buf);

modified libpkg/scripts.c
@@ -32,7 +32,7 @@ pkg_script_pre_install(struct pkg *pkg)
		}
	}

-
	sbuf_clear(script_cmd);
+
	sbuf_delete(script_cmd);

	return (EPKG_OK);
}
@@ -67,7 +67,7 @@ pkg_script_post_install(struct pkg *pkg)
		}
	}

-
	sbuf_clear(script_cmd);
+
	sbuf_delete(script_cmd);

	return (EPKG_OK);
}
@@ -102,7 +102,7 @@ pkg_script_pre_upgrade(struct pkg *pkg)
		}
	}

-
	sbuf_clear(script_cmd);
+
	sbuf_delete(script_cmd);

	return (EPKG_OK);
}
@@ -137,7 +137,7 @@ pkg_script_post_upgrade(struct pkg *pkg)
		}
	}

-
	sbuf_clear(script_cmd);
+
	sbuf_delete(script_cmd);

	return (EPKG_OK);
}
@@ -172,7 +172,7 @@ pkg_script_pre_deinstall(struct pkg *pkg)
		}
	}

-
	sbuf_clear(script_cmd);
+
	sbuf_delete(script_cmd);

	return (EPKG_OK);
}
@@ -207,7 +207,7 @@ pkg_script_post_deinstall(struct pkg *pkg)
		}
	}

-
	sbuf_clear(script_cmd);
+
	sbuf_delete(script_cmd);

	return (EPKG_OK);
}