summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/Makefile.am6
-rw-r--r--lib/libalpm/add.c2
-rw-r--r--lib/libalpm/alpm.c19
-rw-r--r--lib/libalpm/alpm.h3
-rw-r--r--lib/libalpm/be_files.c31
-rw-r--r--lib/libalpm/package.c10
-rw-r--r--lib/libalpm/package.h2
-rw-r--r--lib/libalpm/server.c39
-rw-r--r--lib/libalpm/server.h2
-rw-r--r--lib/libalpm/sync.c1
-rw-r--r--lib/libalpm/util.c79
-rw-r--r--lib/libalpm/util.h1
12 files changed, 131 insertions, 64 deletions
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am
index 9bee7b59..dbdc24db 100644
--- a/lib/libalpm/Makefile.am
+++ b/lib/libalpm/Makefile.am
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = gnu
DEFINES = -pedantic -D_GNU_SOURCE
-AM_CFLAGS = $(DEFINES) -I$(top_srcdir)/lib/libfetch
+AM_CFLAGS = $(DEFINES)
SUBDIRS = po
localedir = $(datadir)/locale
@@ -37,8 +37,8 @@ include_HEADERS = alpm.h
libalpm_la_SOURCES = $(TARGETS)
-libalpm_la_LDFLAGS = -no-undefined -version-info $(PM_VERSION_INFO) -L$(top_srcdir)/lib/libfetch
-libalpm_la_LIBADD = -lfetch
+libalpm_la_LDFLAGS = -no-undefined -version-info $(PM_VERSION_INFO)
+libalpm_la_LIBADD = -ldownload
if HAS_DOXYGEN
all: doxygen.in
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 16cb13a5..4ccac537 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -129,7 +129,7 @@ int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
goto error;
}
- if(_alpm_pkg_splitname(name, pkgname, pkgver) == -1) {
+ if(_alpm_pkg_splitname(name, pkgname, pkgver, 1) == -1) {
pm_errno = PM_ERR_PKG_INVALID_NAME;
goto error;
}
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 37db1394..77f3632e 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -346,9 +346,9 @@ int alpm_db_update(int force, PM_DB *db)
pm_errno = 0;
return(1);
} else if(ret == -1) {
- /* we use fetchLastErrString and fetchLastErrCode here, error returns from
- * libfetch */
- _alpm_log(PM_LOG_DEBUG, _("failed to sync db: %s [%d]"), fetchLastErrString, fetchLastErrCode);
+ /* we use downloadLastErrString and downloadLastErrCode here, error returns from
+ * libdownload */
+ _alpm_log(PM_LOG_DEBUG, _("failed to sync db: %s [%d]"), downloadLastErrString, downloadLastErrCode);
RET_ERR(PM_ERR_DB_SYNC, -1);
} else {
if(strlen(newmtime)) {
@@ -1109,6 +1109,19 @@ int alpm_list_free(pmlist_t *entry)
return(0);
}
+/** Free the outer list, but not the contained data
+ * @param entry list to free
+ * @return 0 on success, -1 on error
+ */
+int alpm_list_free_outer(pmlist_t *entry)
+{
+ ASSERT(entry != NULL, return(-1));
+
+ _FREELIST(entry, NULL);
+
+ return(0);
+}
+
/** Count the entries in a list.
* @param list the list to count
* @return number of entries on success, NULL on error
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index af0dbc31..155d09ad 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -72,7 +72,7 @@ int alpm_release(void);
#define PM_LOG_FLOW1 0x08
#define PM_LOG_FLOW2 0x10
#define PM_LOG_FUNCTION 0x20
-#define PM_LOG_FETCH 0x40
+#define PM_LOG_DOWNLOAD 0x40
int alpm_logaction(char *fmt, ...);
@@ -390,6 +390,7 @@ PM_LIST *alpm_list_first(PM_LIST *list);
PM_LIST *alpm_list_next(PM_LIST *entry);
void *alpm_list_getdata(PM_LIST *entry);
int alpm_list_free(PM_LIST *entry);
+int alpm_list_free_outer(PM_LIST *entry);
int alpm_list_count(PM_LIST *list);
/* md5sums */
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 563f3216..8f81235f 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -163,7 +163,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, unsigned int inforeq)
if(pkg == NULL) {
return(NULL);
}
- if(_alpm_pkg_splitname(ent->d_name, pkg->name, pkg->version) == -1) {
+ if(_alpm_pkg_splitname(ent->d_name, pkg->name, pkg->version, 0) == -1) {
_alpm_log(PM_LOG_ERROR, _("invalid name for dabatase entry '%s'"), ent->d_name);
return(NULL);
}
@@ -180,9 +180,8 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
struct stat buf;
char path[PATH_MAX+1];
char line[513];
- char *lang_tmp;
pmlist_t *tmplist;
- char *foo;
+ char *locale;
if(db == NULL) {
RET_ERR(PM_ERR_DB_NULL, -1);
@@ -225,30 +224,26 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
info->desc_localized = _alpm_list_add(info->desc_localized, strdup(line));
}
- if (setlocale(LC_ALL, "") == NULL) { /* To fix segfault when locale invalid */
+ if((locale = setlocale(LC_ALL, "")) == NULL) { /* To fix segfault when locale invalid */
setenv("LC_ALL", "C", 1);
+ locale = setlocale(LC_ALL, "");
}
- if((lang_tmp = (char *)malloc(strlen(setlocale(LC_ALL, "")))) == NULL) {
- RET_ERR(PM_ERR_MEMORY, -1);
- }
- snprintf(lang_tmp, strlen(setlocale(LC_ALL, "")), "%s", setlocale(LC_ALL, ""));
if(info->desc_localized && !info->desc_localized->next) {
snprintf(info->desc, 512, "%s", (char*)info->desc_localized->data);
} else {
- for (tmplist = info->desc_localized; tmplist; tmplist = tmplist->next) {
- if (tmplist->data && strncmp(tmplist->data, lang_tmp, strlen(lang_tmp))) {
- snprintf(info->desc, 512, "%s", (char*)info->desc_localized->data);
- } else {
- foo = strdup(tmplist->data);
- snprintf(info->desc, 512, "%s", foo+strlen(lang_tmp)+1);
- FREE(foo);
- break;
+ for (tmplist = info->desc_localized; tmplist; tmplist = tmplist->next) {
+ if (tmplist->data && strncmp(tmplist->data, locale, strlen(locale))) {
+ strncpy(info->desc, (char *)info->desc_localized->data, sizeof(info->desc));
+ } else {
+ char *p = (char *)tmplist->data;
+ p += strlen(locale) + 1;
+ strncpy(info->desc, p, sizeof(info->desc));
+ break;
+ }
}
- }
}
_alpm_strtrim(info->desc);
- FREE(lang_tmp);
} else if(!strcmp(line, "%GROUPS%")) {
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
info->groups = _alpm_list_add(info->groups, strdup(line));
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 16e0dc32..2686c00c 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -435,7 +435,7 @@ pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack)
return(NULL);
}
-int _alpm_pkg_splitname(char *target, char *name, char *version)
+int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
{
char tmp[PKG_FULLNAME_LEN+7];
char *p, *q;
@@ -453,7 +453,11 @@ int _alpm_pkg_splitname(char *target, char *name, char *version)
STRNCPY(tmp, p, PKG_FULLNAME_LEN+7);
/* trim file extension (if any) */
if((p = strstr(tmp, PM_EXT_PKG))) {
- *p = 0;
+ *p = '\0';
+ }
+
+ if((p = _alpm_pkgname_has_arch(tmp))) {
+ *p = '\0';
}
p = tmp + strlen(tmp);
@@ -469,7 +473,7 @@ int _alpm_pkg_splitname(char *target, char *name, char *version)
if(version) {
STRNCPY(version, p+1, PKG_VERSION_LEN);
}
- *p = 0;
+ *p = '\0';
if(name) {
STRNCPY(name, tmp, PKG_NAME_LEN);
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 62ad7e4a..6dd092c8 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -98,7 +98,7 @@ void _alpm_pkg_free(void *data);
int _alpm_pkg_cmp(const void *p1, const void *p2);
pmpkg_t *_alpm_pkg_load(char *pkgfile);
pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack);
-int _alpm_pkg_splitname(char *target, char *name, char *version);
+int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch);
#endif /* _ALPM_PACKAGE_H */
diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c
index ce39cb5a..aeaad6ae 100644
--- a/lib/libalpm/server.c
+++ b/lib/libalpm/server.c
@@ -52,7 +52,7 @@ pmserver_t *_alpm_server_new(const char *url)
}
memset(server, 0, sizeof(pmserver_t));
- u = fetchParseURL(url);
+ u = downloadParseURL(url);
if(!u) {
_alpm_log(PM_LOG_ERROR, _("url '%s' is invalid, ignoring"), url);
return(NULL);
@@ -68,7 +68,7 @@ pmserver_t *_alpm_server_new(const char *url)
}
/* This isn't needed... we can actually kill the whole pmserver_t interface
- * and replace it with libfetch's 'struct url'
+ * and replace it with libdownload's 'struct url'
*/
server->s_url = u;
server->path = strdup(u->doc);
@@ -86,7 +86,7 @@ void _alpm_server_free(void *data)
/* free memory */
FREE(server->path);
- fetchFreeURL(server->s_url);
+ downloadFreeURL(server->s_url);
FREE(server);
}
@@ -165,24 +165,24 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath,
server->s_url->doc = (char *)malloc(len);
snprintf(server->s_url->doc, len, "%s/%s", server->path, fn);
- /* libfetch does not reset the error code, reset it in the case of previous errors */
- fetchLastErrCode = 0;
+ /* libdownload does not reset the error code, reset it in the case of previous errors */
+ downloadLastErrCode = 0;
/* 10s timeout - TODO make a config option */
- fetchTimeout = 10000;
+ downloadTimeout = 10000;
- /* Make libfetch super verbose... worthwhile for testing */
- if(pm_logmask & PM_LOG_FETCH) {
- fetchDebug = 1;
+ /* Make libdownload super verbose... worthwhile for testing */
+ if(pm_logmask & PM_LOG_DOWNLOAD) {
+ downloadDebug = 1;
}
if(pm_logmask & PM_LOG_DEBUG) {
- dlf = fetchXGet(server->s_url, &ust, (handle->nopassiveftp ? "v" : "vp"));
+ dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "v" : "vp"));
} else {
- dlf = fetchXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p"));
+ dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p"));
}
- if(fetchLastErrCode != 0 || dlf == NULL) {
+ if(downloadLastErrCode != 0 || dlf == NULL) {
_alpm_log(PM_LOG_ERROR, _("failed retrieving file '%s' from %s://%s: %s"), fn,
- server->s_url->scheme, server->s_url->host, fetchLastErrString);
+ server->s_url->scheme, server->s_url->host, downloadLastErrString);
if(localf != NULL) {
fclose(localf);
}
@@ -321,7 +321,7 @@ char *_alpm_fetch_pkgurl(char *target)
struct stat st;
struct url *s_url;
- s_url = fetchParseURL(target);
+ s_url = downloadParseURL(target);
if(!s_url) {
_alpm_log(PM_LOG_ERROR, _("url '%s' is invalid, ignoring"), target);
return(NULL);
@@ -350,7 +350,7 @@ char *_alpm_fetch_pkgurl(char *target)
}
if(s_url->doc && (p = strrchr(s_url->doc,'/'))) {
*p++ = '\0';
- _alpm_log(PM_LOG_DEBUG, _("fetching '%s' from '%s://%s%s"), p, s_url->scheme, s_url->host, s_url->doc);
+ _alpm_log(PM_LOG_DEBUG, _("downloading '%s' from '%s://%s%s"), p, s_url->scheme, s_url->host, s_url->doc);
server->s_url = s_url;
server->path = strdup(s_url->doc);
@@ -366,10 +366,15 @@ char *_alpm_fetch_pkgurl(char *target)
}
}
- fetchFreeURL(s_url);
+ /* dupe before we free the URL struct...*/
+ if(p) {
+ p = strdup(p);
+ }
+
+ downloadFreeURL(s_url);
/* return the target with the raw filename, no URL */
- return(p ? strdup(p) : NULL);
+ return(p);
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/server.h b/lib/libalpm/server.h
index 73353189..5ce848cc 100644
--- a/lib/libalpm/server.h
+++ b/lib/libalpm/server.h
@@ -24,7 +24,7 @@
#include "list.h"
#include <time.h>
-#include <fetch.h>
+#include <download.h>
#define FREESERVER(p) \
do { \
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index e0f1bc1d..b7ebe6b4 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -451,6 +451,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, pmlist_t *dbs_sync, p
}
}
}
+ FREELISTPTR(k);
FREELISTPTR(trans->packages);
trans->packages = l;
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 2d34ac58..38b0bced 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -243,6 +243,8 @@ int _alpm_lckmk(char *file)
}
}
+ free(dir);
+
return(fd > 0 ? fd : -1);
}
@@ -265,33 +267,34 @@ int _alpm_unpack(const char *archive, const char *prefix, const char *fn)
struct archive_entry *entry;
char expath[PATH_MAX];
- if ((_archive = archive_read_new ()) == NULL)
+ if((_archive = archive_read_new()) == NULL)
RET_ERR(PM_ERR_LIBARCHIVE_ERROR, -1);
archive_read_support_compression_all(_archive);
- archive_read_support_format_all (_archive);
+ archive_read_support_format_all(_archive);
- if (archive_read_open_file (_archive, archive, ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
+ if(archive_read_open_file(_archive, archive, ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK)
RET_ERR(PM_ERR_PKG_OPEN, -1);
- while (archive_read_next_header (_archive, &entry) == ARCHIVE_OK) {
- if (fn && strcmp (fn, archive_entry_pathname (entry))) {
- if (archive_read_data_skip (_archive) != ARCHIVE_OK)
+ while(archive_read_next_header(_archive, &entry) == ARCHIVE_OK) {
+ if (fn && strcmp(fn, archive_entry_pathname(entry))) {
+ if (archive_read_data_skip(_archive) != ARCHIVE_OK)
return(1);
continue;
}
- snprintf(expath, PATH_MAX, "%s/%s", prefix, archive_entry_pathname (entry));
- archive_entry_set_pathname (entry, expath);
- if (archive_read_extract (_archive, entry, ARCHIVE_EXTRACT_FLAGS) != ARCHIVE_OK) {
- fprintf(stderr, _("could not extract %s: %s\n"), archive_entry_pathname (entry), archive_error_string (_archive));
+ snprintf(expath, PATH_MAX, "%s/%s", prefix, archive_entry_pathname(entry));
+ archive_entry_set_pathname(entry, expath);
+ if(archive_read_extract(_archive, entry, ARCHIVE_EXTRACT_FLAGS) != ARCHIVE_OK) {
+ fprintf(stderr, _("could not extract %s: %s\n"), archive_entry_pathname(entry), archive_error_string(_archive));
return(1);
}
- if (fn)
+ if(fn) {
break;
+ }
}
- archive_read_finish (_archive);
+ archive_read_finish(_archive);
return(0);
}
@@ -543,16 +546,20 @@ static long long get_freespace()
FILE *fp;
long long ret=0;
- fp = setmntent (table, "r");
- if(!fp)
- return(-1);
- while ((mnt = getmntent (fp)))
+ if((fp = setmntent(table, "r")) == NULL) {
+ return(-1);
+ }
+
+ while ((mnt = getmntent(fp)))
{
struct statvfs64 buf;
statvfs64(mnt->mnt_dir, &buf);
ret += buf.f_bavail * buf.f_bsize;
}
+
+ endmntent(fp);
+
return(ret);
}
@@ -634,4 +641,44 @@ void _alpm_time2string(time_t t, char *buffer)
}
}
+/* internal */
+char *_supported_archs[] = {
+ "i586",
+ "i686",
+ "ppc",
+ "x86_64",
+};
+
+char *_alpm_pkgname_has_arch(char *pkgname)
+{
+ /* TODO remove this when we transfer everything over to -ARCH
+ *
+ * this parsing sucks... it's done to support
+ * two package formats for the time being:
+ * package-name-foo-1.0.0-1-i686
+ * and
+ * package-name-bar-1.2.3-1
+ */
+ int i = 0;
+ char *arch, *cmp, *p;
+
+ if((p = strrchr(pkgname, '-'))) {
+ for(i=0; i < sizeof(_supported_archs)/sizeof(char*); ++i) {
+ cmp = p+1;
+ arch = _supported_archs[i];
+
+ /* whee, case insensitive compare */
+
+ while(*arch && *cmp && tolower(*arch++) == tolower(*cmp++)) ;
+ if(*arch || *cmp) continue;
+
+ return p;
+ }
+ }
+ return NULL;
+}
+
+
+
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 37b944cb..37a19e89 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -72,6 +72,7 @@ int _alpm_check_freespace(pmtrans_t *trans, pmlist_t **data);
#endif
int _alpm_reg_match(char *string, char *pattern);
void _alpm_time2string(time_t t, char *buffer);
+char *_alpm_pkgname_has_arch(char *pkgname);
#ifdef __sun__
char* strsep(char** str, const char* delims);
char* mkdtemp(char *template);