2009-08-17 22:37:20 +05:30
|
|
|
/*-
|
|
|
|
* Copyright (c) 2008-2009 Juan Romero Pardines.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <xbps_api.h>
|
|
|
|
|
|
|
|
static int unpack_archive_fini(struct archive *, prop_dictionary_t, bool);
|
2009-11-09 07:00:04 +05:30
|
|
|
static int remove_obsoletes(prop_dictionary_t, prop_dictionary_t);
|
2009-09-30 21:59:21 +05:30
|
|
|
static void set_extract_flags(int *);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
2009-10-27 06:16:00 +05:30
|
|
|
int SYMEXPORT
|
2009-08-17 22:37:20 +05:30
|
|
|
xbps_unpack_binary_pkg(prop_dictionary_t pkg, bool essential)
|
|
|
|
{
|
|
|
|
prop_string_t filename, repoloc, arch;
|
|
|
|
struct archive *ar;
|
|
|
|
const char *pkgname;
|
|
|
|
char *binfile;
|
|
|
|
int pkg_fd, rv = 0;
|
|
|
|
|
|
|
|
assert(pkg != NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Append filename to the full path for binary pkg.
|
|
|
|
*/
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
|
|
|
|
return errno;
|
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
filename = prop_dictionary_get(pkg, "filename");
|
|
|
|
arch = prop_dictionary_get(pkg, "architecture");
|
|
|
|
repoloc = prop_dictionary_get(pkg, "repository");
|
|
|
|
if (filename == NULL || arch == NULL || repoloc == NULL)
|
|
|
|
return ENOTSUP;
|
|
|
|
|
|
|
|
binfile = xbps_xasprintf("%s/%s/%s",
|
|
|
|
prop_string_cstring_nocopy(repoloc),
|
|
|
|
prop_string_cstring_nocopy(arch),
|
|
|
|
prop_string_cstring_nocopy(filename));
|
|
|
|
if (binfile == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
if ((pkg_fd = open(binfile, O_RDONLY)) == -1) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
ar = archive_read_new();
|
|
|
|
if (ar == NULL) {
|
|
|
|
rv = ENOMEM;
|
|
|
|
goto out2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable support for tar format and all compression methods.
|
|
|
|
*/
|
|
|
|
archive_read_support_compression_all(ar);
|
|
|
|
archive_read_support_format_tar(ar);
|
|
|
|
|
|
|
|
if ((rv = archive_read_open_fd(ar, pkg_fd,
|
|
|
|
ARCHIVE_READ_BLOCKSIZE)) != 0)
|
|
|
|
goto out3;
|
|
|
|
|
|
|
|
rv = unpack_archive_fini(ar, pkg, essential);
|
|
|
|
/*
|
|
|
|
* If installation of package was successful, make sure the package
|
|
|
|
* is really on storage (if possible).
|
|
|
|
*/
|
|
|
|
if (rv == 0) {
|
2009-08-19 02:20:29 +05:30
|
|
|
if (fsync(pkg_fd) == -1) {
|
|
|
|
rv = errno;
|
|
|
|
goto out3;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Set package state to unpacked.
|
|
|
|
*/
|
|
|
|
rv = xbps_set_pkg_state_installed(pkgname,
|
|
|
|
XBPS_PKG_STATE_UNPACKED);
|
|
|
|
}
|
2009-08-19 02:20:29 +05:30
|
|
|
out3:
|
|
|
|
archive_read_finish(ar);
|
|
|
|
out2:
|
|
|
|
(void)close(pkg_fd);
|
|
|
|
out:
|
|
|
|
free(binfile);
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flags for extracting files in binary packages. If a package
|
|
|
|
* is marked as "essential", its files will be overwritten and then
|
|
|
|
* the old and new dictionaries are compared to find out if there
|
|
|
|
* are some files that were in the old package that should be removed.
|
|
|
|
*/
|
|
|
|
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
2009-10-21 21:46:17 +05:30
|
|
|
ARCHIVE_EXTRACT_SECURE_SYMLINKS | \
|
|
|
|
ARCHIVE_EXTRACT_NO_OVERWRITE | \
|
|
|
|
ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER
|
2009-08-17 22:37:20 +05:30
|
|
|
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
|
|
|
|
ARCHIVE_EXTRACT_TIME | EXTRACT_FLAGS
|
|
|
|
|
|
|
|
static void
|
2009-09-30 21:59:21 +05:30
|
|
|
set_extract_flags(int *flags)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
2009-10-21 21:46:17 +05:30
|
|
|
*flags = 0;
|
2009-08-17 22:37:20 +05:30
|
|
|
if (getuid() == 0)
|
2009-09-30 21:59:21 +05:30
|
|
|
*flags = FEXTRACT_FLAGS;
|
2009-08-17 22:37:20 +05:30
|
|
|
else
|
2009-09-30 21:59:21 +05:30
|
|
|
*flags = EXTRACT_FLAGS;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
install_config_file(prop_dictionary_t d, struct archive_entry *entry,
|
2009-10-21 21:46:17 +05:30
|
|
|
const char *pkgname, int *flags, bool *skip)
|
2009-08-17 22:37:20 +05:30
|
|
|
{
|
|
|
|
prop_dictionary_t forigd;
|
|
|
|
prop_object_t obj, obj2;
|
|
|
|
prop_object_iterator_t iter, iter2;
|
2009-10-21 21:46:17 +05:30
|
|
|
const char *cffile, *sha256_new = NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
char *buf, *sha256_cur = NULL, *sha256_orig = NULL;
|
|
|
|
int rv = 0;
|
|
|
|
bool install_new = false;
|
|
|
|
|
|
|
|
if (d == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
iter = xbps_get_array_iter_from_dict(d, "conf_files");
|
|
|
|
if (iter == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get original hash for the file from current
|
|
|
|
* installed package.
|
|
|
|
*/
|
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/%s", XBPS_META_PATH,
|
|
|
|
pkgname, XBPS_PKGFILES);
|
|
|
|
if (buf == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
forigd = prop_dictionary_internalize_from_file(buf);
|
|
|
|
free(buf);
|
2009-10-10 12:14:37 +05:30
|
|
|
if (forigd == NULL) {
|
|
|
|
install_new = true;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter2 = xbps_get_array_iter_from_dict(forigd, "conf_files");
|
|
|
|
if (iter2 != NULL) {
|
|
|
|
while ((obj2 = prop_object_iterator_next(iter2))) {
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj2,
|
|
|
|
"file", &cffile)) {
|
|
|
|
prop_object_iterator_release(iter2);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-21 21:46:17 +05:30
|
|
|
buf = xbps_xasprintf(".%s", cffile);
|
|
|
|
if (buf == NULL) {
|
|
|
|
prop_object_iterator_release(iter2);
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (strcmp(archive_entry_pathname(entry), buf) == 0) {
|
2009-10-10 12:14:37 +05:30
|
|
|
prop_dictionary_get_cstring(obj2, "sha256",
|
|
|
|
&sha256_orig);
|
2009-10-21 21:46:17 +05:30
|
|
|
free(buf);
|
2009-10-10 12:14:37 +05:30
|
|
|
break;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-10-21 21:46:17 +05:30
|
|
|
free(buf);
|
|
|
|
buf = NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-10-10 12:14:37 +05:30
|
|
|
prop_object_iterator_release(iter2);
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-10-10 12:14:37 +05:30
|
|
|
prop_object_release(forigd);
|
2009-10-21 21:46:17 +05:30
|
|
|
/*
|
|
|
|
* First case: original hash not found, install new file.
|
|
|
|
*/
|
|
|
|
if (sha256_orig == NULL) {
|
|
|
|
install_new = true;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare original, installed and new hash for current file.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"file", &cffile)) {
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return errno;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
buf = xbps_xasprintf(".%s", cffile);
|
|
|
|
if (buf == NULL) {
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return errno;
|
|
|
|
}
|
2009-10-21 21:46:17 +05:30
|
|
|
if (strcmp(archive_entry_pathname(entry), buf)) {
|
|
|
|
free(buf);
|
|
|
|
buf = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
sha256_cur = xbps_get_file_hash(buf);
|
|
|
|
free(buf);
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(obj,
|
|
|
|
"sha256", &sha256_new)) {
|
2009-10-21 21:46:17 +05:30
|
|
|
rv = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
if (sha256_cur == NULL) {
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
/*
|
|
|
|
* File not installed, install new one.
|
|
|
|
*/
|
|
|
|
install_new = true;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
rv = errno;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Orig = X, Curr = X, New = X
|
|
|
|
*
|
|
|
|
* Install new file.
|
|
|
|
*/
|
|
|
|
if ((strcmp(sha256_orig, sha256_cur) == 0) &&
|
2009-10-21 21:46:17 +05:30
|
|
|
(strcmp(sha256_orig, sha256_new) == 0) &&
|
|
|
|
(strcmp(sha256_cur, sha256_new) == 0)) {
|
2009-08-17 22:37:20 +05:30
|
|
|
install_new = true;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Orig = X, Curr = X, New = Y
|
|
|
|
*
|
|
|
|
* Install new file.
|
|
|
|
*/
|
|
|
|
} else if ((strcmp(sha256_orig, sha256_cur) == 0) &&
|
2009-10-21 21:46:17 +05:30
|
|
|
(strcmp(sha256_orig, sha256_new)) &&
|
|
|
|
(strcmp(sha256_cur, sha256_new))) {
|
|
|
|
printf("Updating %s file with new version.\n",
|
|
|
|
cffile);
|
2009-08-17 22:37:20 +05:30
|
|
|
install_new = true;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Orig = X, Curr = Y, New = X
|
|
|
|
*
|
|
|
|
* Keep current file as is.
|
|
|
|
*/
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if ((strcmp(sha256_orig, sha256_new) == 0) &&
|
|
|
|
(strcmp(sha256_cur, sha256_new)) &&
|
|
|
|
(strcmp(sha256_orig, sha256_cur))) {
|
|
|
|
printf("Keeping modified file %s.\n", cffile);
|
|
|
|
*skip = true;
|
2009-08-17 22:37:20 +05:30
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Orig = X, Curr = Y, New = Y
|
|
|
|
*
|
|
|
|
* Install new file.
|
|
|
|
*/
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if ((strcmp(sha256_cur, sha256_new) == 0) &&
|
|
|
|
(strcmp(sha256_orig, sha256_new)) &&
|
|
|
|
(strcmp(sha256_orig, sha256_cur))) {
|
2009-08-17 22:37:20 +05:30
|
|
|
install_new = true;
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Orig = X, Curr = Y, New = Z
|
|
|
|
*
|
|
|
|
* Install new file as file.new.
|
|
|
|
*/
|
|
|
|
} else if ((strcmp(sha256_orig, sha256_cur)) &&
|
|
|
|
(strcmp(sha256_cur, sha256_new)) &&
|
|
|
|
(strcmp(sha256_orig, sha256_new))) {
|
|
|
|
buf = xbps_xasprintf(".%s.new", cffile);
|
|
|
|
if (buf == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
break;
|
|
|
|
}
|
2009-10-21 21:46:17 +05:30
|
|
|
printf("Keeping modified file %s.\n", cffile);
|
|
|
|
printf("Installing new version as %s.new.\n", cffile);
|
2009-08-17 22:37:20 +05:30
|
|
|
install_new = true;
|
|
|
|
archive_entry_set_pathname(entry, buf);
|
|
|
|
free(buf);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-10 12:14:37 +05:30
|
|
|
out:
|
2009-10-21 21:46:17 +05:30
|
|
|
if (install_new) {
|
|
|
|
*flags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE;
|
|
|
|
*flags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
if (sha256_orig)
|
|
|
|
free(sha256_orig);
|
|
|
|
if (sha256_cur)
|
|
|
|
free(sha256_cur);
|
|
|
|
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO: remove printfs and return appropiate errors to be interpreted by
|
|
|
|
* the consumer.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg,
|
|
|
|
bool essential)
|
|
|
|
{
|
2009-11-19 10:40:42 +05:30
|
|
|
prop_dictionary_t filesd = NULL, old_filesd = NULL;
|
2009-08-17 22:37:20 +05:30
|
|
|
struct archive_entry *entry;
|
2009-10-21 21:46:17 +05:30
|
|
|
const char *pkgname, *version, *rootdir, *entry_str;
|
2009-08-17 22:37:20 +05:30
|
|
|
char *buf, *buf2;
|
2009-09-30 21:59:21 +05:30
|
|
|
int rv = 0, flags, lflags;
|
2009-08-17 22:37:20 +05:30
|
|
|
bool actgt = false, skip_entry = false;
|
|
|
|
|
|
|
|
assert(ar != NULL);
|
|
|
|
assert(pkg != NULL);
|
|
|
|
rootdir = xbps_get_rootdir();
|
|
|
|
flags = xbps_get_flags();
|
|
|
|
|
|
|
|
if (strcmp(rootdir, "") == 0)
|
|
|
|
rootdir = "/";
|
|
|
|
|
|
|
|
if (chdir(rootdir) == -1)
|
|
|
|
return errno;
|
|
|
|
|
2009-11-23 15:16:51 +05:30
|
|
|
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
|
|
|
|
return errno;
|
|
|
|
if (!prop_dictionary_get_cstring_nocopy(pkg, "version", &version))
|
|
|
|
return errno;
|
2009-08-17 22:37:20 +05:30
|
|
|
|
|
|
|
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
2009-10-21 21:46:17 +05:30
|
|
|
entry_str = archive_entry_pathname(entry);
|
2009-09-30 21:59:21 +05:30
|
|
|
set_extract_flags(&lflags);
|
2009-10-21 21:46:17 +05:30
|
|
|
if (((strcmp("./INSTALL", entry_str)) == 0) ||
|
|
|
|
((strcmp("./REMOVE", entry_str)) == 0) ||
|
2009-10-21 21:57:18 +05:30
|
|
|
((strcmp("./files.plist", entry_str)) == 0) ||
|
2009-10-21 21:46:17 +05:30
|
|
|
((strcmp("./props.plist", entry_str)) == 0) || essential) {
|
|
|
|
/*
|
|
|
|
* Always overwrite files in essential packages,
|
|
|
|
* and metadata files.
|
|
|
|
*/
|
|
|
|
lflags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE;
|
|
|
|
lflags &= ~ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER;
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the pre INSTALL action if the file is there.
|
|
|
|
*/
|
2009-10-21 21:46:17 +05:30
|
|
|
if (strcmp("./INSTALL", entry_str) == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (buf == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
actgt = true;
|
|
|
|
archive_entry_set_pathname(entry, buf);
|
|
|
|
|
2009-09-30 21:59:21 +05:30
|
|
|
if (archive_read_extract(ar, entry, lflags) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
if ((rv = archive_errno(ar)) != EEXIST) {
|
|
|
|
free(buf);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = xbps_file_chdir_exec(rootdir, buf, "pre",
|
|
|
|
pkgname, version, NULL)) != 0) {
|
|
|
|
free(buf);
|
|
|
|
printf("%s: preinst action target error %s\n",
|
|
|
|
pkgname, strerror(errno));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
/* pass to the next entry if successful */
|
|
|
|
free(buf);
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unpack metadata files in final directory.
|
|
|
|
*/
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if (strcmp("./REMOVE", entry_str) == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
buf2 = xbps_xasprintf(".%s/metadata/%s/REMOVE",
|
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (buf2 == NULL)
|
|
|
|
return errno;
|
|
|
|
archive_entry_set_pathname(entry, buf2);
|
|
|
|
free(buf2);
|
|
|
|
buf2 = NULL;
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if (strcmp("./files.plist", entry_str) == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Now we have a dictionary from the entry
|
|
|
|
* in memory. Will be written to disk later, when
|
|
|
|
* all files are extracted.
|
|
|
|
*/
|
|
|
|
filesd = xbps_read_dict_from_archive_entry(ar, entry);
|
|
|
|
if (filesd == NULL)
|
|
|
|
return errno;
|
|
|
|
|
|
|
|
/* Pass to next entry */
|
|
|
|
continue;
|
|
|
|
|
2009-10-21 21:46:17 +05:30
|
|
|
} else if (strcmp("./props.plist", entry_str) == 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
buf2 = xbps_xasprintf(".%s/metadata/%s/props.plist",
|
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (buf2 == NULL)
|
|
|
|
return errno;
|
|
|
|
archive_entry_set_pathname(entry, buf2);
|
|
|
|
free(buf2);
|
2009-10-21 21:46:17 +05:30
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Handle configuration files.
|
|
|
|
*/
|
|
|
|
if ((rv = install_config_file(filesd, entry, pkgname,
|
|
|
|
&lflags, &skip_entry)) != 0) {
|
|
|
|
prop_object_release(filesd);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
if (skip_entry) {
|
|
|
|
archive_read_data_skip(ar);
|
|
|
|
skip_entry = false;
|
|
|
|
continue;
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
}
|
2009-10-21 21:46:17 +05:30
|
|
|
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Extract entry from archive.
|
|
|
|
*/
|
2009-09-30 21:59:21 +05:30
|
|
|
if (archive_read_extract(ar, entry, lflags) != 0) {
|
2009-08-17 22:37:20 +05:30
|
|
|
rv = archive_errno(ar);
|
|
|
|
if (rv != EEXIST) {
|
|
|
|
printf("ERROR: %s...exiting!\n",
|
|
|
|
archive_error_string(ar));
|
|
|
|
return rv;;
|
|
|
|
} else if (rv == EEXIST) {
|
|
|
|
if (flags & XBPS_FLAG_VERBOSE) {
|
|
|
|
printf("WARNING: ignoring existent "
|
|
|
|
"path: %s\n",
|
|
|
|
archive_entry_pathname(entry));
|
|
|
|
}
|
|
|
|
rv = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (flags & XBPS_FLAG_VERBOSE)
|
|
|
|
printf(" %s\n", archive_entry_pathname(entry));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((rv = archive_errno(ar)) == 0) {
|
2009-11-09 07:00:04 +05:30
|
|
|
buf2 = xbps_xasprintf(".%s/metadata/%s/files.plist",
|
|
|
|
XBPS_META_PATH, pkgname);
|
|
|
|
if (buf2 == NULL) {
|
|
|
|
prop_object_release(filesd);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if files.plist exists and pkg is marked as
|
|
|
|
* essential, in that case we need to check for obsolete
|
|
|
|
* files and remove them if necessary.
|
|
|
|
*/
|
|
|
|
if (essential && (access(buf2, R_OK) == 0)) {
|
|
|
|
old_filesd =
|
|
|
|
prop_dictionary_internalize_from_file(buf2);
|
|
|
|
if (old_filesd == NULL) {
|
|
|
|
prop_object_release(filesd);
|
|
|
|
free(buf2);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
rv = remove_obsoletes(old_filesd, filesd);
|
|
|
|
if (rv != 0) {
|
|
|
|
prop_object_release(old_filesd);
|
|
|
|
prop_object_release(filesd);
|
|
|
|
free(buf2);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
prop_object_release(old_filesd);
|
|
|
|
}
|
2009-08-17 22:37:20 +05:30
|
|
|
/*
|
|
|
|
* Now that all files were successfully unpacked, we
|
|
|
|
* can safely externalize files.plist because the path
|
|
|
|
* is reachable.
|
|
|
|
*/
|
|
|
|
if (!prop_dictionary_externalize_to_file(filesd, buf2)) {
|
|
|
|
prop_object_release(filesd);
|
|
|
|
free(buf2);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
free(buf2);
|
|
|
|
}
|
|
|
|
prop_object_release(filesd);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2009-11-09 07:00:04 +05:30
|
|
|
|
|
|
|
static int
|
|
|
|
remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd)
|
|
|
|
{
|
|
|
|
prop_object_iterator_t iter, iter2;
|
|
|
|
prop_object_t obj, obj2;
|
|
|
|
prop_string_t oldstr, newstr;
|
|
|
|
const char *array_str = "files";
|
|
|
|
char *buf = NULL;
|
|
|
|
int rv = 0;
|
|
|
|
bool found, dolinks = false;
|
|
|
|
|
|
|
|
iter = iter2 = NULL;
|
|
|
|
obj = obj2 = NULL;
|
|
|
|
oldstr = newstr = NULL;
|
|
|
|
|
|
|
|
again:
|
|
|
|
iter = xbps_get_array_iter_from_dict(oldd, array_str);
|
|
|
|
if (iter == NULL)
|
|
|
|
return errno;
|
|
|
|
iter2 = xbps_get_array_iter_from_dict(newd, array_str);
|
|
|
|
if (iter2 == NULL) {
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check for obsolete files, i.e files/links available in
|
|
|
|
* the old package list not found in new package list.
|
|
|
|
*/
|
|
|
|
while ((obj = prop_object_iterator_next(iter))) {
|
|
|
|
found = false;
|
|
|
|
oldstr = prop_dictionary_get(obj, "file");
|
2009-11-23 15:16:51 +05:30
|
|
|
if (oldstr == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-09 07:00:04 +05:30
|
|
|
while ((obj2 = prop_object_iterator_next(iter2))) {
|
|
|
|
newstr = prop_dictionary_get(obj2, "file");
|
2009-11-23 15:16:51 +05:30
|
|
|
if (newstr == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-11-09 07:00:04 +05:30
|
|
|
if (prop_string_equals(oldstr, newstr)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop_object_iterator_reset(iter2);
|
|
|
|
if (found)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Obsolete file found, remove it.
|
|
|
|
*/
|
|
|
|
buf = xbps_xasprintf(".%s", prop_string_cstring_nocopy(oldstr));
|
|
|
|
if (buf == NULL) {
|
|
|
|
rv = errno;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (remove(buf) == -1) {
|
|
|
|
printf("WARNING: couldn't remove obsolete %s: %s\n",
|
|
|
|
dolinks ? "link" : "file",
|
|
|
|
prop_string_cstring_nocopy(oldstr));
|
|
|
|
free(buf);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
printf("Removed obsolete %s: %s\n",
|
|
|
|
dolinks ? "link" : "file",
|
|
|
|
prop_string_cstring_nocopy(oldstr));
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
if (!dolinks) {
|
|
|
|
/*
|
|
|
|
* Now look for obsolete links.
|
|
|
|
*/
|
|
|
|
dolinks = true;
|
|
|
|
array_str = "links";
|
|
|
|
prop_object_iterator_release(iter2);
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
iter = iter2 = NULL;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
prop_object_iterator_release(iter2);
|
|
|
|
prop_object_iterator_release(iter);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|