unpack: use archive_entry_{filetype,uid,gid,mode} rather than stored struct stat.
This commit is contained in:
parent
a6c26f6c12
commit
57bb7baf5e
@ -48,7 +48,7 @@
|
|||||||
*/
|
*/
|
||||||
#define XBPS_PKGINDEX_VERSION "1.7"
|
#define XBPS_PKGINDEX_VERSION "1.7"
|
||||||
|
|
||||||
#define XBPS_API_VERSION "20130310"
|
#define XBPS_API_VERSION "20130315"
|
||||||
|
|
||||||
#ifndef XBPS_VERSION
|
#ifndef XBPS_VERSION
|
||||||
#define XBPS_VERSION "UNSET"
|
#define XBPS_VERSION "UNSET"
|
||||||
|
@ -91,7 +91,6 @@ unpack_archive(struct xbps_handle *xhp,
|
|||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
prop_data_t data;
|
prop_data_t data;
|
||||||
void *instbuf = NULL, *rembuf = NULL;
|
void *instbuf = NULL, *rembuf = NULL;
|
||||||
const struct stat *entry_statp;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct xbps_unpack_cb_data xucd;
|
struct xbps_unpack_cb_data xucd;
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
@ -99,7 +98,7 @@ unpack_archive(struct xbps_handle *xhp,
|
|||||||
ssize_t entry_size;
|
ssize_t entry_size;
|
||||||
const char *file, *entry_pname, *transact, *tgtlnk;
|
const char *file, *entry_pname, *transact, *tgtlnk;
|
||||||
char *pkgname, *dname, *buf, *buf2, *p, *p2;
|
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 preserve, update, conf_file, file_exists, skip_obsoletes;
|
||||||
bool softreplace, skip_extract, force;
|
bool softreplace, skip_extract, force;
|
||||||
uid_t euid;
|
uid_t euid;
|
||||||
@ -152,6 +151,7 @@ unpack_archive(struct xbps_handle *xhp,
|
|||||||
/*
|
/*
|
||||||
* Process the archive files.
|
* Process the archive files.
|
||||||
*/
|
*/
|
||||||
|
flags = set_extract_flags(euid);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
ar_rv = archive_read_next_header(ar, &entry);
|
ar_rv = archive_read_next_header(ar, &entry);
|
||||||
if (ar_rv == ARCHIVE_EOF || ar_rv == ARCHIVE_FATAL)
|
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)
|
else if (ar_rv == ARCHIVE_RETRY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
entry_statp = archive_entry_stat(entry);
|
|
||||||
entry_pname = archive_entry_pathname(entry);
|
entry_pname = archive_entry_pathname(entry);
|
||||||
entry_size = archive_entry_size(entry);
|
entry_size = archive_entry_size(entry);
|
||||||
flags = set_extract_flags(euid);
|
entry_type = archive_entry_filetype(entry);
|
||||||
/*
|
/*
|
||||||
* Ignore directories from archive.
|
* Ignore directories from archive.
|
||||||
*/
|
*/
|
||||||
if (S_ISDIR(entry_statp->st_mode)) {
|
if (entry_type == AE_IFDIR) {
|
||||||
archive_read_data_skip(ar);
|
archive_read_data_skip(ar);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -291,7 +290,7 @@ unpack_archive(struct xbps_handle *xhp,
|
|||||||
if (lstat(entry_pname, &st) == 0)
|
if (lstat(entry_pname, &st) == 0)
|
||||||
file_exists = true;
|
file_exists = true;
|
||||||
|
|
||||||
if (!force && S_ISREG(entry_statp->st_mode)) {
|
if (!force && (entry_type == AE_IFREG)) {
|
||||||
buf = strchr(entry_pname, '.') + 1;
|
buf = strchr(entry_pname, '.') + 1;
|
||||||
assert(buf != NULL);
|
assert(buf != NULL);
|
||||||
if (file_exists) {
|
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
|
* Check if current link from binpkg hasn't been
|
||||||
* modified, otherwise extract new link.
|
* modified, otherwise extract new link.
|
||||||
@ -386,9 +385,9 @@ unpack_archive(struct xbps_handle *xhp,
|
|||||||
* in binpkg and apply perms if true.
|
* in binpkg and apply perms if true.
|
||||||
*/
|
*/
|
||||||
if (!force && file_exists && skip_extract &&
|
if (!force && file_exists && skip_extract &&
|
||||||
(entry_statp->st_mode != st.st_mode)) {
|
(archive_entry_mode(entry) != st.st_mode)) {
|
||||||
if (chmod(entry_pname,
|
if (chmod(entry_pname,
|
||||||
entry_statp->st_mode) != 0) {
|
archive_entry_mode(entry)) != 0) {
|
||||||
xbps_dbg_printf(xhp,
|
xbps_dbg_printf(xhp,
|
||||||
"%s: failed "
|
"%s: failed "
|
||||||
"to set perms %s to %s: %s\n",
|
"to set perms %s to %s: %s\n",
|
||||||
@ -407,19 +406,22 @@ unpack_archive(struct xbps_handle *xhp,
|
|||||||
* and change permissions if true.
|
* and change permissions if true.
|
||||||
*/
|
*/
|
||||||
if ((!force && file_exists && skip_extract && (euid == 0)) &&
|
if ((!force && file_exists && skip_extract && (euid == 0)) &&
|
||||||
(((entry_statp->st_uid != st.st_uid)) ||
|
(((archive_entry_uid(entry) != st.st_uid)) ||
|
||||||
((entry_statp->st_gid != st.st_gid)))) {
|
((archive_entry_gid(entry) != st.st_gid)))) {
|
||||||
if (chown(entry_pname,
|
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,
|
xbps_dbg_printf(xhp,
|
||||||
"%s: failed "
|
"%s: failed "
|
||||||
"to set uid/gid to %u:%u (%s)\n",
|
"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));
|
strerror(errno));
|
||||||
} else {
|
} else {
|
||||||
xbps_dbg_printf(xhp, "%s: entry %s changed "
|
xbps_dbg_printf(xhp, "%s: entry %s changed "
|
||||||
"uid/gid to %u:%u.\n", pkgver, entry_pname,
|
"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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user