2005-03-14 20:51:43 -05:00
|
|
|
/*
|
|
|
|
* package.c
|
2006-10-15 15:31:03 -04:00
|
|
|
*
|
2006-01-02 14:55:35 -05:00
|
|
|
* Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
|
2006-10-15 15:31:03 -04:00
|
|
|
* Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
|
|
|
|
* Copyright (c) 2005, 2006 by Christian Hamar <krics@linuxforum.hu>
|
|
|
|
* Copyright (c) 2005, 2006 by Miklos Vajna <vmiklos@frugalware.org>
|
2005-03-14 20:51:43 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
|
|
* USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
2006-05-14 22:19:57 -04:00
|
|
|
#include <libintl.h>
|
2006-10-15 15:31:03 -04:00
|
|
|
#include <locale.h>
|
2005-03-14 20:51:43 -05:00
|
|
|
/* pacman */
|
|
|
|
#include "log.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "package.h"
|
2005-03-28 03:21:17 -05:00
|
|
|
#include "alpm.h"
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
pmpkg_t *_alpm_pkg_new(const char *name, const char *version)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
pmpkg_t* pkg = NULL;
|
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
if((pkg = (pmpkg_t *)malloc(sizeof(pmpkg_t))) == NULL) {
|
|
|
|
RET_ERR(PM_ERR_MEMORY, (pmpkg_t *)-1);
|
2006-02-20 15:41:40 -05:00
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-01-09 15:16:00 -05:00
|
|
|
if(name && name[0] != 0) {
|
|
|
|
STRNCPY(pkg->name, name, PKG_NAME_LEN);
|
|
|
|
} else {
|
|
|
|
pkg->name[0] = '\0';
|
|
|
|
}
|
|
|
|
if(version && version[0] != 0) {
|
|
|
|
STRNCPY(pkg->version, version, PKG_VERSION_LEN);
|
|
|
|
} else {
|
|
|
|
pkg->version[0] = '\0';
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
pkg->desc[0] = '\0';
|
|
|
|
pkg->url[0] = '\0';
|
2005-08-20 01:54:45 -04:00
|
|
|
pkg->license = NULL;
|
2006-10-15 15:31:03 -04:00
|
|
|
pkg->desc_localized = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
pkg->builddate[0] = '\0';
|
2006-10-15 15:31:03 -04:00
|
|
|
pkg->buildtype[0] = '\0';
|
2005-03-14 20:51:43 -05:00
|
|
|
pkg->installdate[0] = '\0';
|
|
|
|
pkg->packager[0] = '\0';
|
|
|
|
pkg->md5sum[0] = '\0';
|
2006-10-15 15:31:03 -04:00
|
|
|
pkg->sha1sum[0] = '\0';
|
2005-03-14 20:51:43 -05:00
|
|
|
pkg->arch[0] = '\0';
|
|
|
|
pkg->size = 0;
|
2006-10-15 15:31:03 -04:00
|
|
|
pkg->usize = 0;
|
2005-03-14 20:51:43 -05:00
|
|
|
pkg->scriptlet = 0;
|
|
|
|
pkg->force = 0;
|
2006-01-10 13:19:06 -05:00
|
|
|
pkg->reason = PM_PKG_REASON_EXPLICIT;
|
2005-03-14 20:51:43 -05:00
|
|
|
pkg->requiredby = NULL;
|
|
|
|
pkg->conflicts = NULL;
|
|
|
|
pkg->files = NULL;
|
|
|
|
pkg->backup = NULL;
|
|
|
|
pkg->depends = NULL;
|
2006-10-15 15:31:03 -04:00
|
|
|
pkg->removes = NULL;
|
2005-03-14 20:51:43 -05:00
|
|
|
pkg->groups = NULL;
|
|
|
|
pkg->provides = NULL;
|
|
|
|
pkg->replaces = NULL;
|
|
|
|
/* internal */
|
|
|
|
pkg->origin = 0;
|
|
|
|
pkg->data = NULL;
|
|
|
|
pkg->infolevel = 0;
|
|
|
|
|
|
|
|
return(pkg);
|
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg)
|
2005-04-23 13:18:31 -04:00
|
|
|
{
|
|
|
|
pmpkg_t* newpkg = NULL;
|
|
|
|
|
|
|
|
newpkg = (pmpkg_t *)malloc(sizeof(pmpkg_t));
|
|
|
|
if(newpkg == NULL) {
|
2006-05-14 22:19:57 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), sizeof(pmpkg_t));
|
2006-03-07 15:52:45 -05:00
|
|
|
RET_ERR(PM_ERR_MEMORY, NULL);
|
2005-04-23 13:18:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
STRNCPY(newpkg->name, pkg->name, PKG_NAME_LEN);
|
|
|
|
STRNCPY(newpkg->version, pkg->version, PKG_VERSION_LEN);
|
|
|
|
STRNCPY(newpkg->desc, pkg->desc, PKG_DESC_LEN);
|
|
|
|
STRNCPY(newpkg->url, pkg->url, PKG_URL_LEN);
|
|
|
|
STRNCPY(newpkg->builddate, pkg->builddate, PKG_DATE_LEN);
|
2006-10-15 15:31:03 -04:00
|
|
|
STRNCPY(newpkg->buildtype, pkg->buildtype, PKG_DATE_LEN);
|
2005-04-23 13:18:31 -04:00
|
|
|
STRNCPY(newpkg->installdate, pkg->installdate, PKG_DATE_LEN);
|
|
|
|
STRNCPY(newpkg->packager, pkg->packager, PKG_PACKAGER_LEN);
|
|
|
|
STRNCPY(newpkg->md5sum, pkg->md5sum, PKG_MD5SUM_LEN);
|
2006-10-15 15:31:03 -04:00
|
|
|
STRNCPY(newpkg->sha1sum, pkg->sha1sum, PKG_SHA1SUM_LEN);
|
2005-04-23 13:18:31 -04:00
|
|
|
STRNCPY(newpkg->arch, pkg->arch, PKG_ARCH_LEN);
|
|
|
|
newpkg->size = pkg->size;
|
2006-10-15 15:31:03 -04:00
|
|
|
newpkg->usize = pkg->usize;
|
2005-04-23 13:18:31 -04:00
|
|
|
newpkg->force = pkg->force;
|
|
|
|
newpkg->scriptlet = pkg->scriptlet;
|
|
|
|
newpkg->reason = pkg->reason;
|
2005-07-21 21:59:11 -04:00
|
|
|
newpkg->license = _alpm_list_strdup(pkg->license);
|
2006-10-15 15:31:03 -04:00
|
|
|
newpkg->desc_localized = _alpm_list_strdup(pkg->desc_localized);
|
2005-04-23 13:18:31 -04:00
|
|
|
newpkg->requiredby = _alpm_list_strdup(pkg->requiredby);
|
|
|
|
newpkg->conflicts = _alpm_list_strdup(pkg->conflicts);
|
|
|
|
newpkg->files = _alpm_list_strdup(pkg->files);
|
|
|
|
newpkg->backup = _alpm_list_strdup(pkg->backup);
|
|
|
|
newpkg->depends = _alpm_list_strdup(pkg->depends);
|
2006-10-15 15:31:03 -04:00
|
|
|
newpkg->removes = _alpm_list_strdup(pkg->removes);
|
2005-04-23 13:18:31 -04:00
|
|
|
newpkg->groups = _alpm_list_strdup(pkg->groups);
|
|
|
|
newpkg->provides = _alpm_list_strdup(pkg->provides);
|
|
|
|
newpkg->replaces = _alpm_list_strdup(pkg->replaces);
|
|
|
|
/* internal */
|
|
|
|
newpkg->origin = pkg->origin;
|
|
|
|
newpkg->data = (newpkg->origin == PKG_FROM_FILE) ? strdup(pkg->data) : pkg->data;
|
|
|
|
newpkg->infolevel = pkg->infolevel;
|
|
|
|
|
|
|
|
return(newpkg);
|
|
|
|
}
|
|
|
|
|
2006-02-22 15:49:33 -05:00
|
|
|
void _alpm_pkg_free(void *data)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2006-02-22 15:49:33 -05:00
|
|
|
pmpkg_t *pkg = data;
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
if(pkg == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-12-28 05:15:55 -05:00
|
|
|
FREELIST(pkg->license);
|
2006-10-15 15:31:03 -04:00
|
|
|
FREELIST(pkg->desc_localized);
|
2005-03-14 20:51:43 -05:00
|
|
|
FREELIST(pkg->files);
|
|
|
|
FREELIST(pkg->backup);
|
|
|
|
FREELIST(pkg->depends);
|
2006-10-15 15:31:03 -04:00
|
|
|
FREELIST(pkg->removes);
|
2005-03-14 20:51:43 -05:00
|
|
|
FREELIST(pkg->conflicts);
|
|
|
|
FREELIST(pkg->requiredby);
|
|
|
|
FREELIST(pkg->groups);
|
|
|
|
FREELIST(pkg->provides);
|
|
|
|
FREELIST(pkg->replaces);
|
|
|
|
if(pkg->origin == PKG_FROM_FILE) {
|
|
|
|
FREE(pkg->data);
|
|
|
|
}
|
2006-10-31 01:39:59 -05:00
|
|
|
FREE(pkg);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-08 13:07:58 -05:00
|
|
|
/* Helper function for comparing packages
|
|
|
|
*/
|
|
|
|
int _alpm_pkg_cmp(const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
return(strcmp(((pmpkg_t *)p1)->name, ((pmpkg_t *)p2)->name));
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* Parses the package description file for the current package
|
|
|
|
*
|
|
|
|
* Returns: 0 on success, 1 on error
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int parse_descfile(char *descfile, pmpkg_t *info, int output)
|
|
|
|
{
|
|
|
|
FILE* fp = NULL;
|
2006-02-16 16:02:39 -05:00
|
|
|
char line[PATH_MAX];
|
2005-03-14 20:51:43 -05:00
|
|
|
char* ptr = NULL;
|
|
|
|
char* key = NULL;
|
|
|
|
int linenum = 0;
|
|
|
|
|
|
|
|
if((fp = fopen(descfile, "r")) == NULL) {
|
2006-05-14 22:19:57 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("could not open file %s"), descfile);
|
2005-03-14 20:51:43 -05:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!feof(fp)) {
|
|
|
|
fgets(line, PATH_MAX, fp);
|
|
|
|
linenum++;
|
|
|
|
_alpm_strtrim(line);
|
|
|
|
if(strlen(line) == 0 || line[0] == '#') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(output) {
|
2005-03-28 03:21:17 -05:00
|
|
|
_alpm_log(PM_LOG_DEBUG, "%s", line);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
ptr = line;
|
|
|
|
key = strsep(&ptr, "=");
|
|
|
|
if(key == NULL || ptr == NULL) {
|
2006-10-15 15:31:03 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, _("%s: syntax error in description file line %d"),
|
2005-03-14 20:51:43 -05:00
|
|
|
info->name[0] != '\0' ? info->name : "error", linenum);
|
|
|
|
} else {
|
|
|
|
_alpm_strtrim(key);
|
|
|
|
key = _alpm_strtoupper(key);
|
|
|
|
_alpm_strtrim(ptr);
|
|
|
|
if(!strcmp(key, "PKGNAME")) {
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(info->name, ptr, sizeof(info->name));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "PKGVER")) {
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(info->version, ptr, sizeof(info->version));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "PKGDESC")) {
|
2006-10-15 15:31:03 -04:00
|
|
|
char *lang_tmp;
|
|
|
|
info->desc_localized = _alpm_list_add(info->desc_localized, strdup(ptr));
|
|
|
|
if((lang_tmp = (char *)malloc(strlen(setlocale(LC_ALL, "")))) == NULL) {
|
|
|
|
RET_ERR(PM_ERR_MEMORY, -1);
|
|
|
|
}
|
|
|
|
STRNCPY(lang_tmp, setlocale(LC_ALL, ""), strlen(setlocale(LC_ALL, "")));
|
|
|
|
if(info->desc_localized && !info->desc_localized->next) {
|
|
|
|
STRNCPY(info->desc, ptr, sizeof(info->desc));
|
|
|
|
} else if (ptr && !strncmp(ptr, lang_tmp, strlen(lang_tmp))) {
|
|
|
|
STRNCPY(info->desc, ptr+strlen(lang_tmp)+1, sizeof(info->desc));
|
|
|
|
}
|
|
|
|
FREE(lang_tmp);
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "GROUP")) {
|
2006-02-17 17:35:26 -05:00
|
|
|
info->groups = _alpm_list_add(info->groups, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "URL")) {
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(info->url, ptr, sizeof(info->url));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "LICENSE")) {
|
2006-02-17 17:35:26 -05:00
|
|
|
info->license = _alpm_list_add(info->license, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "BUILDDATE")) {
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(info->builddate, ptr, sizeof(info->builddate));
|
2006-10-15 15:31:03 -04:00
|
|
|
} else if(!strcmp(key, "BUILDTYPE")) {
|
|
|
|
STRNCPY(info->buildtype, ptr, sizeof(info->buildtype));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "INSTALLDATE")) {
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(info->installdate, ptr, sizeof(info->installdate));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "PACKAGER")) {
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(info->packager, ptr, sizeof(info->packager));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "ARCH")) {
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(info->arch, ptr, sizeof(info->arch));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "SIZE")) {
|
|
|
|
char tmp[32];
|
2005-03-29 12:18:59 -05:00
|
|
|
STRNCPY(tmp, ptr, sizeof(tmp));
|
2005-03-14 20:51:43 -05:00
|
|
|
info->size = atol(tmp);
|
2006-10-15 15:31:03 -04:00
|
|
|
} else if(!strcmp(key, "USIZE")) {
|
|
|
|
char tmp[32];
|
|
|
|
STRNCPY(tmp, ptr, sizeof(tmp));
|
|
|
|
info->usize = atol(tmp);
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "DEPEND")) {
|
2006-02-17 17:35:26 -05:00
|
|
|
info->depends = _alpm_list_add(info->depends, strdup(ptr));
|
2006-10-15 15:31:03 -04:00
|
|
|
} else if(!strcmp(key, "REMOVE")) {
|
|
|
|
info->removes = _alpm_list_add(info->removes, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "CONFLICT")) {
|
2006-02-17 17:35:26 -05:00
|
|
|
info->conflicts = _alpm_list_add(info->conflicts, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "REPLACES")) {
|
2006-02-17 17:35:26 -05:00
|
|
|
info->replaces = _alpm_list_add(info->replaces, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "PROVIDES")) {
|
2006-02-17 17:35:26 -05:00
|
|
|
info->provides = _alpm_list_add(info->provides, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else if(!strcmp(key, "BACKUP")) {
|
2006-02-17 17:35:26 -05:00
|
|
|
info->backup = _alpm_list_add(info->backup, strdup(ptr));
|
2005-03-14 20:51:43 -05:00
|
|
|
} else {
|
2006-10-15 15:31:03 -04:00
|
|
|
_alpm_log(PM_LOG_DEBUG, _("%s: syntax error in description file line %d"),
|
2005-03-14 20:51:43 -05:00
|
|
|
info->name[0] != '\0' ? info->name : "error", linenum);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line[0] = '\0';
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
unlink(descfile);
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
pmpkg_t *_alpm_pkg_load(char *pkgfile)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
|
|
|
char *expath;
|
|
|
|
int i;
|
|
|
|
int config = 0;
|
|
|
|
int filelist = 0;
|
|
|
|
int scriptcheck = 0;
|
2006-09-28 16:51:33 -04:00
|
|
|
register struct archive *archive;
|
|
|
|
struct archive_entry *entry;
|
2005-03-14 20:51:43 -05:00
|
|
|
pmpkg_t *info = NULL;
|
|
|
|
|
2005-04-17 06:00:49 -04:00
|
|
|
if(pkgfile == NULL || strlen(pkgfile) == 0) {
|
2005-03-16 17:10:05 -05:00
|
|
|
RET_ERR(PM_ERR_WRONG_ARGS, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
if ((archive = archive_read_new ()) == NULL)
|
|
|
|
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, NULL);
|
|
|
|
|
|
|
|
archive_read_support_compression_all (archive);
|
|
|
|
archive_read_support_format_all (archive);
|
|
|
|
|
|
|
|
if (archive_read_open_file (archive, pkgfile, ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
|
|
|
|
RET_ERR(PM_ERR_PKG_OPEN, NULL);
|
|
|
|
|
2006-02-17 17:35:26 -05:00
|
|
|
info = _alpm_pkg_new(NULL, NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
if(info == NULL) {
|
2006-10-15 15:31:03 -04:00
|
|
|
archive_read_finish (archive);
|
|
|
|
RET_ERR(PM_ERR_MEMORY, NULL);
|
2006-09-28 16:51:33 -04:00
|
|
|
}
|
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
for(i = 0; archive_read_next_header (archive, &entry) == ARCHIVE_OK; i++) {
|
2005-03-14 20:51:43 -05:00
|
|
|
if(config && filelist && scriptcheck) {
|
|
|
|
/* we have everything we need */
|
|
|
|
break;
|
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
if(!strcmp(archive_entry_pathname (entry), ".PKGINFO")) {
|
2005-03-14 20:51:43 -05:00
|
|
|
char *descfile;
|
2005-11-09 16:50:47 -05:00
|
|
|
int fd;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
/* extract this file into /tmp. it has info for us */
|
2005-03-27 02:42:21 -05:00
|
|
|
descfile = strdup("/tmp/alpm_XXXXXX");
|
2005-11-09 16:50:47 -05:00
|
|
|
fd = mkstemp(descfile);
|
2006-10-15 15:31:03 -04:00
|
|
|
archive_read_data_into_fd (archive, fd);
|
2005-03-14 20:51:43 -05:00
|
|
|
/* parse the info file */
|
|
|
|
if(parse_descfile(descfile, info, 0) == -1) {
|
2006-05-14 22:19:57 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("could not parse the package description file"));
|
2005-11-07 04:43:25 -05:00
|
|
|
pm_errno = PM_ERR_PKG_INVALID;
|
2005-11-09 16:50:47 -05:00
|
|
|
unlink(descfile);
|
2005-04-24 17:36:18 -04:00
|
|
|
FREE(descfile);
|
2005-11-09 16:50:47 -05:00
|
|
|
close(fd);
|
2005-03-14 20:51:43 -05:00
|
|
|
goto error;
|
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
if(!strlen(info->name)) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, _("missing package name in %s"), pkgfile);
|
|
|
|
pm_errno = PM_ERR_PKG_INVALID;
|
|
|
|
unlink(descfile);
|
|
|
|
FREE(descfile);
|
|
|
|
close(fd);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if(!strlen(info->version)) {
|
|
|
|
_alpm_log(PM_LOG_ERROR, _("missing package version in %s"), pkgfile);
|
|
|
|
pm_errno = PM_ERR_PKG_INVALID;
|
|
|
|
unlink(descfile);
|
|
|
|
FREE(descfile);
|
|
|
|
close(fd);
|
|
|
|
goto error;
|
|
|
|
}
|
2005-03-14 20:51:43 -05:00
|
|
|
config = 1;
|
2005-11-09 16:50:47 -05:00
|
|
|
unlink(descfile);
|
2005-03-14 20:51:43 -05:00
|
|
|
FREE(descfile);
|
2005-11-09 16:50:47 -05:00
|
|
|
close(fd);
|
2005-03-14 20:51:43 -05:00
|
|
|
continue;
|
2006-10-15 15:31:03 -04:00
|
|
|
} else if(!strcmp(archive_entry_pathname (entry), "._install") || !strcmp(archive_entry_pathname (entry), ".INSTALL")) {
|
2005-03-14 20:51:43 -05:00
|
|
|
info->scriptlet = 1;
|
|
|
|
scriptcheck = 1;
|
2006-10-15 15:31:03 -04:00
|
|
|
} else if(!strcmp(archive_entry_pathname (entry), ".FILELIST")) {
|
2005-03-14 20:51:43 -05:00
|
|
|
/* Build info->files from the filelist */
|
|
|
|
FILE *fp;
|
|
|
|
char *fn;
|
|
|
|
char *str;
|
2005-11-09 16:50:47 -05:00
|
|
|
int fd;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
if((str = (char *)malloc(PATH_MAX)) == NULL) {
|
|
|
|
RET_ERR(PM_ERR_MEMORY, (pmpkg_t *)-1);
|
2006-02-20 15:41:40 -05:00
|
|
|
}
|
2005-03-27 02:42:21 -05:00
|
|
|
fn = strdup("/tmp/alpm_XXXXXX");
|
2005-11-09 16:50:47 -05:00
|
|
|
fd = mkstemp(fn);
|
2006-10-15 15:31:03 -04:00
|
|
|
archive_read_data_into_fd (archive,fd);
|
2005-03-14 20:51:43 -05:00
|
|
|
fp = fopen(fn, "r");
|
|
|
|
while(!feof(fp)) {
|
|
|
|
if(fgets(str, PATH_MAX, fp) == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_alpm_strtrim(str);
|
2006-02-17 17:35:26 -05:00
|
|
|
info->files = _alpm_list_add(info->files, strdup(str));
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
FREE(str);
|
|
|
|
fclose(fp);
|
|
|
|
if(unlink(fn)) {
|
2006-05-14 22:19:57 -04:00
|
|
|
_alpm_log(PM_LOG_WARNING, _("could not remove tempfile %s"), fn);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
FREE(fn);
|
2005-11-09 16:50:47 -05:00
|
|
|
close(fd);
|
2005-03-14 20:51:43 -05:00
|
|
|
filelist = 1;
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
scriptcheck = 1;
|
|
|
|
if(!filelist) {
|
|
|
|
/* no .FILELIST present in this package.. build the filelist the */
|
|
|
|
/* old-fashioned way, one at a time */
|
2006-10-15 15:31:03 -04:00
|
|
|
expath = strdup(archive_entry_pathname (entry));
|
2006-02-17 17:35:26 -05:00
|
|
|
info->files = _alpm_list_add(info->files, expath);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-15 15:31:03 -04:00
|
|
|
if(archive_read_data_skip (archive)) {
|
2006-05-14 22:19:57 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("bad package file in %s"), pkgfile);
|
2005-03-14 20:51:43 -05:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
expath = NULL;
|
|
|
|
}
|
2006-10-15 15:31:03 -04:00
|
|
|
archive_read_finish (archive);
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(!config) {
|
2006-05-14 22:19:57 -04:00
|
|
|
_alpm_log(PM_LOG_ERROR, _("missing package info file in %s"), pkgfile);
|
2005-03-14 20:51:43 -05:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* internal */
|
|
|
|
info->origin = PKG_FROM_FILE;
|
|
|
|
info->data = strdup(pkgfile);
|
|
|
|
info->infolevel = 0xFF;
|
|
|
|
|
|
|
|
return(info);
|
|
|
|
|
|
|
|
error:
|
|
|
|
FREEPKG(info);
|
2006-10-15 15:31:03 -04:00
|
|
|
archive_read_finish (archive);
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
|
2006-10-20 02:26:55 -04:00
|
|
|
/* Test for existence of a package in a pmlist_t*
|
2005-03-14 20:51:43 -05:00
|
|
|
* of pmpkg_t*
|
|
|
|
*/
|
2006-10-20 02:26:55 -04:00
|
|
|
pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack)
|
2005-03-14 20:51:43 -05:00
|
|
|
{
|
2006-10-20 02:26:55 -04:00
|
|
|
pmlist_t *lp;
|
2005-03-14 20:51:43 -05:00
|
|
|
|
|
|
|
if(needle == NULL || haystack == NULL) {
|
2006-01-18 17:37:16 -05:00
|
|
|
return(NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for(lp = haystack; lp; lp = lp->next) {
|
|
|
|
pmpkg_t *info = lp->data;
|
|
|
|
|
2006-01-18 17:37:16 -05:00
|
|
|
if(info && !strcmp(info->name, needle)) {
|
|
|
|
return(lp->data);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
}
|
2006-01-18 17:37:16 -05:00
|
|
|
return(NULL);
|
2005-03-14 20:51:43 -05:00
|
|
|
}
|
|
|
|
|
2006-11-14 02:58:42 -05:00
|
|
|
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
|
2005-04-08 16:43:13 -04:00
|
|
|
{
|
2005-10-05 16:49:32 -04:00
|
|
|
char tmp[PKG_FULLNAME_LEN+7];
|
2005-04-08 16:43:13 -04:00
|
|
|
char *p, *q;
|
|
|
|
|
|
|
|
if(target == NULL) {
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* trim path name (if any) */
|
|
|
|
if((p = strrchr(target, '/')) == NULL) {
|
|
|
|
p = target;
|
|
|
|
} else {
|
|
|
|
p++;
|
|
|
|
}
|
2005-10-05 16:49:32 -04:00
|
|
|
STRNCPY(tmp, p, PKG_FULLNAME_LEN+7);
|
2005-04-08 16:43:13 -04:00
|
|
|
/* trim file extension (if any) */
|
|
|
|
if((p = strstr(tmp, PM_EXT_PKG))) {
|
2006-11-14 02:58:42 -05:00
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if((p = _alpm_pkgname_has_arch(tmp))) {
|
|
|
|
*p = '\0';
|
2005-04-08 16:43:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
p = tmp + strlen(tmp);
|
|
|
|
|
|
|
|
for(q = --p; *q && *q != '-'; q--);
|
|
|
|
if(*q != '-' || q == tmp) {
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
for(p = --q; *p && *p != '-'; p--);
|
|
|
|
if(*p != '-' || p == tmp) {
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
if(version) {
|
|
|
|
STRNCPY(version, p+1, PKG_VERSION_LEN);
|
|
|
|
}
|
2006-11-14 02:58:42 -05:00
|
|
|
*p = '\0';
|
2005-04-08 16:43:13 -04:00
|
|
|
|
|
|
|
if(name) {
|
|
|
|
STRNCPY(name, tmp, PKG_NAME_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2005-03-14 20:51:43 -05:00
|
|
|
/* vim: set ts=2 sw=2 noet: */
|