unpack: use archive_entry_{filetype,uid,gid,mode} rather than stored struct stat.

This commit is contained in:
Juan RP 2013-03-15 13:18:30 +01:00
parent a6c26f6c12
commit 57bb7baf5e
2 changed files with 17 additions and 15 deletions

View File

@ -48,7 +48,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.7"
#define XBPS_API_VERSION "20130310"
#define XBPS_API_VERSION "20130315"
#ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET"

View File

@ -91,7 +91,6 @@ unpack_archive(struct xbps_handle *xhp,
prop_object_t obj;
prop_data_t data;
void *instbuf = NULL, *rembuf = NULL;
const struct stat *entry_statp;
struct stat st;
struct xbps_unpack_cb_data xucd;
struct archive_entry *entry;
@ -99,7 +98,7 @@ unpack_archive(struct xbps_handle *xhp,
ssize_t entry_size;
const char *file, *entry_pname, *transact, *tgtlnk;
char *pkgname, *dname, *buf, *buf2, *p, *p2;
int ar_rv, rv, flags;
int ar_rv, rv, entry_type, flags;
bool preserve, update, conf_file, file_exists, skip_obsoletes;
bool softreplace, skip_extract, force;
uid_t euid;
@ -152,6 +151,7 @@ unpack_archive(struct xbps_handle *xhp,
/*
* Process the archive files.
*/
flags = set_extract_flags(euid);
for (;;) {
ar_rv = archive_read_next_header(ar, &entry);
if (ar_rv == ARCHIVE_EOF || ar_rv == ARCHIVE_FATAL)
@ -159,14 +159,13 @@ unpack_archive(struct xbps_handle *xhp,
else if (ar_rv == ARCHIVE_RETRY)
continue;
entry_statp = archive_entry_stat(entry);
entry_pname = archive_entry_pathname(entry);
entry_size = archive_entry_size(entry);
flags = set_extract_flags(euid);
entry_type = archive_entry_filetype(entry);
/*
* Ignore directories from archive.
*/
if (S_ISDIR(entry_statp->st_mode)) {
if (entry_type == AE_IFDIR) {
archive_read_data_skip(ar);
continue;
}
@ -291,7 +290,7 @@ unpack_archive(struct xbps_handle *xhp,
if (lstat(entry_pname, &st) == 0)
file_exists = true;
if (!force && S_ISREG(entry_statp->st_mode)) {
if (!force && (entry_type == AE_IFREG)) {
buf = strchr(entry_pname, '.') + 1;
assert(buf != NULL);
if (file_exists) {
@ -343,7 +342,7 @@ unpack_archive(struct xbps_handle *xhp,
}
}
}
} else if (!force && S_ISLNK(entry_statp->st_mode)) {
} else if (!force && (entry_type == AE_IFLNK)) {
/*
* Check if current link from binpkg hasn't been
* modified, otherwise extract new link.
@ -386,9 +385,9 @@ unpack_archive(struct xbps_handle *xhp,
* in binpkg and apply perms if true.
*/
if (!force && file_exists && skip_extract &&
(entry_statp->st_mode != st.st_mode)) {
(archive_entry_mode(entry) != st.st_mode)) {
if (chmod(entry_pname,
entry_statp->st_mode) != 0) {
archive_entry_mode(entry)) != 0) {
xbps_dbg_printf(xhp,
"%s: failed "
"to set perms %s to %s: %s\n",
@ -407,19 +406,22 @@ unpack_archive(struct xbps_handle *xhp,
* and change permissions if true.
*/
if ((!force && file_exists && skip_extract && (euid == 0)) &&
(((entry_statp->st_uid != st.st_uid)) ||
((entry_statp->st_gid != st.st_gid)))) {
(((archive_entry_uid(entry) != st.st_uid)) ||
((archive_entry_gid(entry) != st.st_gid)))) {
if (chown(entry_pname,
entry_statp->st_uid, entry_statp->st_gid) != 0) {
archive_entry_uid(entry),
archive_entry_gid(entry)) != 0) {
xbps_dbg_printf(xhp,
"%s: failed "
"to set uid/gid to %u:%u (%s)\n",
pkgver, entry_statp->st_uid, entry_statp->st_gid,
pkgver, archive_entry_uid(entry),
archive_entry_gid(entry),
strerror(errno));
} else {
xbps_dbg_printf(xhp, "%s: entry %s changed "
"uid/gid to %u:%u.\n", pkgver, entry_pname,
entry_statp->st_uid, entry_statp->st_gid);
archive_entry_uid(entry),
archive_entry_gid(entry));
}
}