summaryrefslogtreecommitdiff
path: root/lib/libalpm/be_files.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libalpm/be_files.c')
-rw-r--r--lib/libalpm/be_files.c131
1 files changed, 23 insertions, 108 deletions
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 83b6072c..8998f678 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -27,9 +27,6 @@
#include <stdlib.h>
#include <errno.h>
#include <string.h>
-#ifdef __sun__
-#include <strings.h>
-#endif
#include <sys/stat.h>
#include <dirent.h>
#ifdef CYGWIN
@@ -56,7 +53,7 @@ int _alpm_db_install(pmdb_t *db, const char *dbfile)
/* TODO we should not simply unpack the archive, but better parse it and
* db_write each entry (see sync_load_dbarchive to get archive content) */
- _alpm_log(PM_LOG_DEBUG, _("unpacking database '%s'"), dbfile);
+ _alpm_log(PM_LOG_DEBUG, "unpacking database '%s'\n", dbfile);
if(_alpm_unpack(dbfile, db->path, NULL)) {
RET_ERR(PM_ERR_SYSTEM, -1);
@@ -65,38 +62,6 @@ int _alpm_db_install(pmdb_t *db, const char *dbfile)
return unlink(dbfile);
}
-alpm_list_t *_alpm_db_test(pmdb_t *db)
-{
- struct dirent *ent;
- char path[PATH_MAX];
- char text[PATH_MAX+1];
- struct stat buf;
- alpm_list_t *ret = NULL;
-
- while ((ent = readdir(db->handle)) != NULL) {
- if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, "..")) {
- continue;
- }
- /* check for desc, depends, and files */
- snprintf(path, PATH_MAX, "%s/%s/desc", db->path, ent->d_name);
- if(stat(path, &buf)) {
- snprintf(text, PATH_MAX, _("%s: description file is missing"), ent->d_name);
- ret = alpm_list_add(ret, strdup(text));
- }
- snprintf(path, PATH_MAX, "%s/%s/depends", db->path, ent->d_name);
- if(stat(path, &buf)) {
- snprintf(text, PATH_MAX, _("%s: dependency file is missing"), ent->d_name);
- ret = alpm_list_add(ret, strdup(text));
- }
- snprintf(path, PATH_MAX, "%s/%s/files", db->path, ent->d_name);
- if(stat(path, &buf)) {
- snprintf(text, PATH_MAX, _("%s: file list is missing"), ent->d_name);
- ret = alpm_list_add(ret, strdup(text));
- }
- }
- return(ret);
-}
-
int _alpm_db_open(pmdb_t *db)
{
ALPM_LOG_FUNC;
@@ -105,7 +70,7 @@ int _alpm_db_open(pmdb_t *db)
RET_ERR(PM_ERR_DB_NULL, -1);
}
- _alpm_log(PM_LOG_DEBUG, _("opening database from path '%s'"), db->path);
+ _alpm_log(PM_LOG_DEBUG, "opening database from path '%s'\n", db->path);
db->handle = opendir(db->path);
if(db->handle == NULL) {
RET_ERR(PM_ERR_DB_OPEN, -1);
@@ -209,11 +174,11 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target)
pkg = _alpm_pkg_new(NULL, NULL);
if(pkg == NULL) {
- _alpm_log(PM_LOG_DEBUG, _("db scan could not find package: %s"), target);
+ _alpm_log(PM_LOG_DEBUG, "db scan could not find package: %s\n", target);
return(NULL);
}
if(_alpm_pkg_splitname(ent->d_name, pkg->name, pkg->version, 0) == -1) {
- _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'"), ent->d_name);
+ _alpm_log(PM_LOG_ERROR, _("invalid name for database entry '%s'\n"), ent->d_name);
alpm_pkg_free(pkg);
pkg = NULL;
continue;
@@ -224,8 +189,8 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target)
/* TODO removed corrupt entry from the FS here */
_alpm_pkg_free(pkg);
} else {
- pkg->data = db;
pkg->origin = PKG_FROM_CACHE;
+ pkg->origin_data.db = db;
}
}
@@ -238,10 +203,6 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
struct stat buf;
char path[PATH_MAX+1];
char line[513];
- /*
- alpm_list_t *tmplist;
- char *locale;
- */
ALPM_LOG_FUNC;
@@ -250,12 +211,12 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
}
if(info == NULL || info->name[0] == 0 || info->version[0] == 0) {
- _alpm_log(PM_LOG_DEBUG, _("invalid package entry provided to _alpm_db_read, skipping"));
+ _alpm_log(PM_LOG_DEBUG, "invalid package entry provided to _alpm_db_read, skipping\n");
return(-1);
}
if(info->origin == PKG_FROM_FILE) {
- _alpm_log(PM_LOG_DEBUG, _("request to read database info for a file-based package '%s', skipping..."), info->name);
+ _alpm_log(PM_LOG_DEBUG, "request to read database info for a file-based package '%s', skipping...\n", info->name);
return(-1);
}
@@ -268,7 +229,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* already loaded this info, do nothing */
return(0);
}
- _alpm_log(PM_LOG_FUNCTION, _("loading package data for %s : level=%d"), info->name, inforeq);
+ _alpm_log(PM_LOG_FUNCTION, _("loading package data for %s : level=%d\n"), info->name, inforeq);
/* clear out 'line', to be certain - and to make valgrind happy */
memset(line, 0, 513);
@@ -276,7 +237,8 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
if(stat(path, &buf)) {
/* directory doesn't exist or can't be opened */
- _alpm_log(PM_LOG_DEBUG, _("cannot find '%s-%s' in db '%s'"), info->name, info->version, db->treename);
+ _alpm_log(PM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n",
+ info->name, info->version, db->treename);
return(-1);
}
@@ -284,7 +246,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(inforeq & INFRQ_DESC) {
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
if((fp = fopen(path, "r")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
goto error;
}
while(!feof(fp)) {
@@ -305,32 +267,6 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(fgets(info->desc, sizeof(info->desc), fp) == NULL) {
goto error;
}
- /*
- while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
- info->desc_localized = alpm_list_add(info->desc_localized, strdup(line));
- PKG_
- }
-
- if((locale = setlocale(LC_ALL, "")) == NULL) { //To fix segfault when locale invalid
- setenv("LC_ALL", "C", 1);
- locale = 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, 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);
} else if(!strcmp(line, "%GROUPS%")) {
while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) {
@@ -355,11 +291,6 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
goto error;
}
_alpm_strtrim(info->builddate);
- } else if(!strcmp(line, "%BUILDTYPE%")) {
- if(fgets(info->buildtype, sizeof(info->buildtype), fp) == NULL) {
- goto error;
- }
- _alpm_strtrim(info->buildtype);
} else if(!strcmp(line, "%INSTALLDATE%")) {
if(fgets(info->installdate, sizeof(info->installdate), fp) == NULL) {
goto error;
@@ -398,12 +329,6 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
}
_alpm_strtrim(tmp);
info->isize = atol(tmp);
- } else if(!strcmp(line, "%SHA1SUM%")) {
- /* SHA1SUM tag only appears in sync repositories,
- * not the local one. */
- if(fgets(info->sha1sum, sizeof(info->sha1sum), fp) == NULL) {
- goto error;
- }
} else if(!strcmp(line, "%MD5SUM%")) {
/* MD5SUM tag only appears in sync repositories,
* not the local one. */
@@ -430,7 +355,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(inforeq & INFRQ_FILES) {
snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, info->name, info->version);
if((fp = fopen(path, "r")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
goto error;
}
while(fgets(line, 256, fp)) {
@@ -453,7 +378,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
if(inforeq & INFRQ_DEPENDS) {
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
if((fp = fopen(path, "r")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
goto error;
}
while(!feof(fp)) {
@@ -541,22 +466,17 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* DESC */
if(inforeq & INFRQ_DESC) {
- _alpm_log(PM_LOG_DEBUG, _("writing %s-%s DESC information back to db"), info->name, info->version);
+ _alpm_log(PM_LOG_DEBUG, "writing %s-%s DESC information back to db\n",
+ info->name, info->version);
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
retval = -1;
goto cleanup;
}
fprintf(fp, "%%NAME%%\n%s\n\n"
"%%VERSION%%\n%s\n\n", info->name, info->version);
if(info->desc[0]) {
- /*fputs("%DESC%\n", fp);
- for(lp = info->desc_localized; lp; lp = lp->next) {
- fprintf(fp, "%s\n", (char *)lp->data);
- }
- fprintf(fp, "\n");
- */
fprintf(fp, "%%DESC%%\n"
"%s\n\n", info->desc);
}
@@ -587,10 +507,6 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
fprintf(fp, "%%BUILDDATE%%\n"
"%s\n\n", info->builddate);
}
- if(info->buildtype[0]) {
- fprintf(fp, "%%BUILDTYPE%%\n"
- "%s\n\n", info->buildtype);
- }
if(info->installdate[0]) {
fprintf(fp, "%%INSTALLDATE%%\n"
"%s\n\n", info->installdate);
@@ -617,10 +533,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
fprintf(fp, "%%ISIZE%%\n"
"%lu\n\n", info->isize);
}
- if(info->sha1sum) {
- fprintf(fp, "%%SHA1SUM%%\n"
- "%s\n\n", info->sha1sum);
- } else if(info->md5sum) {
+ if(info->md5sum) {
fprintf(fp, "%%MD5SUM%%\n"
"%s\n\n", info->md5sum);
}
@@ -631,10 +544,11 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* FILES */
if(local && (inforeq & INFRQ_FILES)) {
- _alpm_log(PM_LOG_DEBUG, _("writing %s-%s FILES information back to db"), info->name, info->version);
+ _alpm_log(PM_LOG_DEBUG, "writing %s-%s FILES information back to db\n",
+ info->name, info->version);
snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
retval = -1;
goto cleanup;
}
@@ -658,10 +572,11 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq)
/* DEPENDS */
if(inforeq & INFRQ_DEPENDS) {
- _alpm_log(PM_LOG_DEBUG, _("writing %s-%s DEPENDS information back to db"), info->name, info->version);
+ _alpm_log(PM_LOG_DEBUG, "writing %s-%s DEPENDS information back to db\n",
+ info->name, info->version);
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
if((fp = fopen(path, "w")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s"), path, strerror(errno));
+ _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
retval = -1;
goto cleanup;
}