summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Griffin <aaronmgriffin@gmail.com>2007-11-14 19:22:06 -0600
committerDan McGee <dan@archlinux.org>2007-11-25 14:03:13 -0600
commit6e8daa553bbd50ec541add9549bfd95030c335f5 (patch)
tree9f4f10b0a3563bb510a045cc06c56d9b87290fd3
parentc7879e77a716edc725858e316ea9d2fa00056d4d (diff)
downloadpacman-6e8daa553bbd50ec541add9549bfd95030c335f5.tar.xz
Force mode of all database files to 644
In the case of a packaging error where install or changelog had bad permissions, pacman respected the original permissions without trying to fix it - this means that some operations (changelog) artificially required root permissions to run In addition, minor function housekeeping on _alpm_unpack Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
-rw-r--r--lib/libalpm/util.c35
1 files changed, 24 insertions, 11 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index a04256ef..2a429488 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -370,12 +370,11 @@ int _alpm_lckrm()
int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
{
- register struct archive *_archive;
+ int ret = 0;
+ mode_t oldmask;
+ struct archive *_archive;
struct archive_entry *entry;
char expath[PATH_MAX];
- const int archive_flags = ARCHIVE_EXTRACT_OWNER |
- ARCHIVE_EXTRACT_PERM |
- ARCHIVE_EXTRACT_TIME;
ALPM_LOG_FUNC;
@@ -392,26 +391,38 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
RET_ERR(PM_ERR_PKG_OPEN, -1);
}
+ oldmask = umask(0022);
while(archive_read_next_header(_archive, &entry) == ARCHIVE_OK) {
+ const struct stat *st;
const char *entryname; /* the name of the file in the archive */
+
+ st = archive_entry_stat(entry);
entryname = archive_entry_pathname(entry);
+
+ if(S_ISREG(st->st_mode)) {
+ archive_entry_set_mode(entry, 0644);
+ }
if (fn && strcmp(fn, entryname)) {
- if (archive_read_data_skip(_archive) != ARCHIVE_OK)
- return(1);
+ if (archive_read_data_skip(_archive) != ARCHIVE_OK) {
+ ret = 1;
+ goto cleanup;
+ }
continue;
}
snprintf(expath, PATH_MAX, "%s/%s", prefix, entryname);
archive_entry_set_pathname(entry, expath);
- int ret = archive_read_extract(_archive, entry, archive_flags);
- if(ret == ARCHIVE_WARN) {
+
+ int readret = archive_read_extract(_archive, entry, 0);
+ if(readret == ARCHIVE_WARN) {
/* operation succeeded but a non-critical error was encountered */
_alpm_log(PM_LOG_DEBUG, "warning extracting %s (%s)\n",
entryname, archive_error_string(_archive));
- } else if(ret != ARCHIVE_OK) {
+ } else if(readret != ARCHIVE_OK) {
_alpm_log(PM_LOG_ERROR, _("could not extract %s (%s)\n"),
entryname, archive_error_string(_archive));
- return(1);
+ ret = 1;
+ goto cleanup;
}
if(fn) {
@@ -419,8 +430,10 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
}
}
+cleanup:
+ umask(oldmask);
archive_read_finish(_archive);
- return(0);
+ return(ret);
}
/* does the same thing as 'rm -rf' */