Implemented support for pre-remove and post-install messages.
Close #44
This commit is contained in:
@@ -160,6 +160,54 @@ out:
|
||||
xbps_object_release(array);
|
||||
}
|
||||
|
||||
static void
|
||||
process_file(const char *file, const char *key)
|
||||
{
|
||||
void *blob;
|
||||
FILE *f;
|
||||
struct stat st;
|
||||
size_t len;
|
||||
xbps_data_t data;
|
||||
|
||||
if ((f = fopen(file, "r")) == NULL)
|
||||
return;
|
||||
|
||||
if (fstat(fileno(f), &st) == -1) {
|
||||
fclose(f);
|
||||
die("lstat %s", file);
|
||||
}
|
||||
|
||||
if (S_ISREG(st.st_mode) == 0) {
|
||||
fclose(f);
|
||||
return;
|
||||
}
|
||||
|
||||
len = st.st_size;
|
||||
|
||||
if ((blob = malloc(len)) == NULL) {
|
||||
fclose(f);
|
||||
die("malloc %s", file);
|
||||
}
|
||||
|
||||
if (fread(blob, len, 1, f) != len) {
|
||||
if (ferror(f)) {
|
||||
fclose(f);
|
||||
die("fread %s", file);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
if ((data = xbps_data_create_data(blob, len)) == NULL)
|
||||
die("xbps_data_create_data %s", file);
|
||||
|
||||
free(blob);
|
||||
|
||||
if (!xbps_dictionary_set(pkg_propsd, key, data))
|
||||
die("xbps_dictionary_set %s", key);
|
||||
|
||||
xbps_object_release(data);
|
||||
}
|
||||
|
||||
static bool
|
||||
entry_is_conf_file(const char *file)
|
||||
{
|
||||
@@ -190,6 +238,8 @@ ftw_cb(const char *fpath, const struct stat *sb, int type, struct FTW *ftwbuf _u
|
||||
|
||||
/* Ignore metadata files generated by xbps-src and destdir */
|
||||
if ((strcmp(fpath, ".") == 0) ||
|
||||
(strcmp(fpath, "./INSTALL.msg") == 0) ||
|
||||
(strcmp(fpath, "./REMOVE.msg") == 0) ||
|
||||
(strcmp(fpath, "./props.plist") == 0) ||
|
||||
(strcmp(fpath, "./files.plist") == 0) ||
|
||||
(strcmp(fpath, "./flist") == 0) ||
|
||||
@@ -754,6 +804,10 @@ main(int argc, char **argv)
|
||||
|
||||
if (chdir(destdir) == -1)
|
||||
die("cannot chdir() to destdir %s:", destdir);
|
||||
|
||||
/* Optional INSTALL/REMOVE messages */
|
||||
process_file("INSTALL.msg", "install-msg");
|
||||
process_file("REMOVE.msg", "remove-msg");
|
||||
/*
|
||||
* Process XBPS_PKGFILES metadata file.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user