Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/Makefile.am12
-rw-r--r--lib/libalpm/alpm.c30
-rw-r--r--lib/libalpm/alpm.h3
-rw-r--r--lib/libalpm/db.c18
-rw-r--r--lib/libalpm/db.h2
-rw-r--r--lib/libalpm/handle.c19
-rw-r--r--lib/libalpm/handle.h1
-rw-r--r--lib/libalpm/md5driver.c2
-rw-r--r--lib/libalpm/package.c6
-rw-r--r--lib/libalpm/server.c2
-rw-r--r--lib/libalpm/sync.c27
-rw-r--r--lib/libalpm/util.c6
-rw-r--r--lib/libalpm/util.h4
13 files changed, 79 insertions, 53 deletions
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am
index 0381d9d8..285a9a83 100644
--- a/lib/libalpm/Makefile.am
+++ b/lib/libalpm/Makefile.am
@@ -2,11 +2,19 @@ AUTOMAKE_OPTIONS = gnu
SUBDIRS = po
+# paths set at make time
+lockfile = ${localstatedir}/run/pacman.lck
+dbpath = ${localstatedir}/lib/pacman/
+cachedir = ${localstatedir}/cache/pacman/pkg/
+
lib_LTLIBRARIES = libalpm.la
include_HEADERS = alpm_list.h alpm.h
-localedir = $(datadir)/locale
-DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
+DEFS = -DLOCALEDIR=\"@localedir@\" \
+ -DLOCKFILE=\"$(lockfile)\" \
+ -DDBPATH=\"$(dbpath)\" \
+ -DCACHEDIR=\"$(cachedir)\" \
+ @DEFS@
AM_CFLAGS = -fvisibility=hidden -pedantic -D_GNU_SOURCE
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index cc7ef32d..ff180210 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -247,6 +247,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
alpm_list_t *files = NULL;
char newmtime[16] = "";
char lastupdate[16] = "";
+ const char *dbpath;
int ret;
ALPM_LOG_FUNC;
@@ -275,12 +276,12 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
}
/* build a one-element list */
- snprintf(path, PATH_MAX, "%s" PM_EXT_DB, db->treename);
+ snprintf(path, PATH_MAX, "%s" DBEXT, db->treename);
files = alpm_list_add(files, strdup(path));
- snprintf(path, PATH_MAX, "%s%s", handle->root, handle->dbpath);
+ dbpath = alpm_option_get_dbpath();
- ret = _alpm_downloadfiles_forreal(db->servers, path, files, lastupdate, newmtime);
+ ret = _alpm_downloadfiles_forreal(db->servers, dbpath, files, lastupdate, newmtime);
FREELIST(files);
if(ret == 1) {
/* mtimes match, do nothing */
@@ -296,7 +297,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
_alpm_log(PM_LOG_DEBUG, _("sync: new mtime for %s: %s"), db->treename, newmtime);
_alpm_db_setlastupdate(db, newmtime);
}
- snprintf(path, PATH_MAX, "%s%s%s" PM_EXT_DB, handle->root, handle->dbpath, db->treename);
+ snprintf(path, PATH_MAX, "%s%s" DBEXT, dbpath, db->treename);
/* remove the old dir */
_alpm_log(PM_LOG_DEBUG, _("flushing database %s%s"), db->path);
@@ -466,8 +467,7 @@ int alpm_pkg_checksha1sum(pmpkg_t *pkg)
ASSERT(pkg->origin == PKG_FROM_CACHE, RET_ERR(PM_ERR_PKG_INVALID, -1));
ASSERT(pkg->data != handle->db_local, RET_ERR(PM_ERR_PKG_INVALID, -1));
- snprintf(path, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG,
- handle->root, handle->cachedir,
+ snprintf(path, PATH_MAX, "%s/%s-%s" PKGEXT, handle->cachedir,
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
sha1sum = _alpm_SHAFile(path);
@@ -510,8 +510,7 @@ int alpm_pkg_checkmd5sum(pmpkg_t *pkg)
ASSERT(pkg->origin == PKG_FROM_CACHE, RET_ERR(PM_ERR_PKG_INVALID, -1));
ASSERT(pkg->data != handle->db_local, RET_ERR(PM_ERR_PKG_INVALID, -1));
- snprintf(path, PATH_MAX, "%s%s/%s-%s" PM_EXT_PKG,
- handle->root, handle->cachedir,
+ snprintf(path, PATH_MAX, "%s/%s-%s" PKGEXT, handle->cachedir,
alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
md5sum = _alpm_MDFile(path);
@@ -639,8 +638,6 @@ int SYMEXPORT alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress)
{
- char path[PATH_MAX];
-
ALPM_LOG_FUNC;
/* Sanity checks */
@@ -649,8 +646,7 @@ int SYMEXPORT alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
/* lock db */
- snprintf(path, PATH_MAX, "%s%s", handle->root, PM_LOCK);
- handle->lckfd = _alpm_lckmk(path);
+ handle->lckfd = _alpm_lckmk();
if(handle->lckfd == -1) {
RET_ERR(PM_ERR_HANDLE_LOCK, -1);
}
@@ -752,7 +748,6 @@ int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
int SYMEXPORT alpm_trans_release()
{
pmtrans_t *trans;
- char path[PATH_MAX];
ALPM_LOG_FUNC;
@@ -780,10 +775,11 @@ int SYMEXPORT alpm_trans_release()
close(handle->lckfd);
handle->lckfd = -1;
}
- snprintf(path, PATH_MAX, "%s%s", handle->root, PM_LOCK);
- if(_alpm_lckrm(path)) {
- _alpm_log(PM_LOG_WARNING, _("could not remove lock file %s"), path);
- alpm_logaction(_("warning: could not remove lock file %s"), path);
+ if(_alpm_lckrm()) {
+ _alpm_log(PM_LOG_WARNING, _("could not remove lock file %s"),
+ alpm_option_get_lockfile());
+ alpm_logaction(_("warning: could not remove lock file %s"),
+ alpm_option_get_lockfile());
}
return(0);
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index e2d2b0e1..4d551c8f 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -106,6 +106,9 @@ void alpm_option_set_cachedir(const char *cachedir);
const char *alpm_option_get_logfile();
void alpm_option_set_logfile(const char *logfile);
+const char *alpm_option_get_lockfile();
+void alpm_option_set_lockfile(const char *lockfile);
+
unsigned short alpm_option_get_usesyslog();
void alpm_option_set_usesyslog(unsigned short usesyslog);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index a1c1121d..0aa8de18 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -52,9 +52,10 @@
#include "cache.h"
#include "alpm.h"
-pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename)
+pmdb_t *_alpm_db_new(const char *dbpath, const char *treename)
{
pmdb_t *db;
+ const size_t pathsize = strlen(dbpath) + strlen(treename) + 2;
ALPM_LOG_FUNC;
@@ -65,14 +66,14 @@ pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename)
RET_ERR(PM_ERR_MEMORY, NULL);
}
- db->path = calloc(1, strlen(root)+strlen(dbpath)+strlen(treename)+2);
+ db->path = calloc(1, pathsize);
if(db->path == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
- strlen(root)+strlen(dbpath)+strlen(treename)+2);
+ pathsize);
FREE(db);
RET_ERR(PM_ERR_MEMORY, NULL);
}
- sprintf(db->path, "%s%s%s/", root, dbpath, treename);
+ sprintf(db->path, "%s%s/", dbpath, treename);
strncpy(db->treename, treename, PATH_MAX);
@@ -160,6 +161,7 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
{
struct stat buf;
pmdb_t *db;
+ const char *dbpath;
char path[PATH_MAX];
ALPM_LOG_FUNC;
@@ -183,15 +185,17 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
_alpm_log(PM_LOG_DEBUG, _("registering database '%s'"), treename);
/* make sure the database directory exists */
- snprintf(path, PATH_MAX, "%s%s/%s", handle->root, handle->dbpath, treename);
+ dbpath = alpm_option_get_dbpath();
+ snprintf(path, PATH_MAX, "%s%s", dbpath, treename);
if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
- _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"), path);
+ _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"),
+ path);
if(_alpm_makepath(path) != 0) {
RET_ERR(PM_ERR_SYSTEM, NULL);
}
}
- db = _alpm_db_new(handle->root, handle->dbpath, treename);
+ db = _alpm_db_new(handle->dbpath, treename);
if(db == NULL) {
RET_ERR(PM_ERR_DB_CREATE, NULL);
}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 26f1fdf4..1cc90309 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -48,7 +48,7 @@ struct __pmdb_t {
};
/* db.c, database general calls */
-pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename);
+pmdb_t *_alpm_db_new(const char *dbpath, const char *treename);
void _alpm_db_free(pmdb_t *db);
int _alpm_db_cmp(const void *db1, const void *db2);
alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles);
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 47abcb32..7eb8dc36 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -79,9 +79,10 @@ pmhandle_t *_alpm_handle_new()
handle->access = PM_ACCESS_RW;
#endif
- handle->root = strdup(PM_ROOT);
- handle->dbpath = strdup(PM_DBPATH);
- handle->cachedir = strdup(PM_CACHEDIR);
+ handle->root = strdup(ROOTDIR);
+ handle->dbpath = strdup(DBPATH);
+ handle->cachedir = strdup(CACHEDIR);
+ handle->lockfile = strdup(LOCKFILE);
handle->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
return(handle);
@@ -111,6 +112,7 @@ void _alpm_handle_free(pmhandle_t *handle)
FREE(handle->dbpath);
FREE(handle->cachedir);
FREE(handle->logfile);
+ FREE(handle->lockfile);
FREE(handle->xfercommand);
FREELIST(handle->dbs_sync);
FREELIST(handle->noupgrade);
@@ -126,7 +128,8 @@ unsigned short SYMEXPORT alpm_option_get_logmask() { return handle->logmask; }
const char SYMEXPORT *alpm_option_get_root() { return handle->root; }
const char SYMEXPORT *alpm_option_get_dbpath() { return handle->dbpath; }
const char SYMEXPORT *alpm_option_get_cachedir() { return handle->cachedir; }
-const char *alpm_option_get_logfile() { return handle->logfile; }
+const char SYMEXPORT *alpm_option_get_logfile() { return handle->logfile; }
+const char SYMEXPORT *alpm_option_get_lockfile() { return handle->lockfile; }
unsigned short alpm_option_get_usesyslog() { return handle->usesyslog; }
alpm_list_t *alpm_option_get_noupgrades() { return handle->noupgrade; }
alpm_list_t *alpm_option_get_noextracts() { return handle->noextract; }
@@ -228,6 +231,14 @@ void alpm_option_set_logfile(const char *logfile)
}
}
+void SYMEXPORT alpm_option_set_lockfile(const char *lockfile)
+{
+ if(handle->lockfile) FREE(handle->lockfile);
+ if(lockfile) {
+ handle->lockfile = strdup(lockfile);
+ }
+}
+
void alpm_option_set_usesyslog(unsigned short usesyslog)
{
handle->usesyslog = usesyslog;
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 0790ad13..b3311db6 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -52,6 +52,7 @@ typedef struct _pmhandle_t {
char *dbpath; /* Base path to pacman's DBs */
char *cachedir; /* Base path to pacman's cache */
char *logfile; /* Name of the file to log to */ /*TODO is this used?*/
+ char *lockfile; /* Name of the lock file */
unsigned short usesyslog; /* Use syslog instead of logfile? */
alpm_list_t *noupgrade; /* List of packages NOT to be upgraded */
diff --git a/lib/libalpm/md5driver.c b/lib/libalpm/md5driver.c
index 4ef3c352..80b90564 100644
--- a/lib/libalpm/md5driver.c
+++ b/lib/libalpm/md5driver.c
@@ -52,7 +52,7 @@ char* _alpm_MDFile(char *filename)
ALPM_LOG_FUNC;
if((file = fopen(filename, "rb")) == NULL) {
- _alpm_log(PM_LOG_ERROR, _("%s can't be opened\n"), filename);
+ _alpm_log(PM_LOG_ERROR, _("md5: %s can't be opened\n"), filename);
} else {
char *ret;
int i;
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index d3547dfb..99ce92b8 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -502,7 +502,7 @@ int _alpm_pkg_splitname(const char *target, char *name, char *version, int witha
}
strncpy(tmp, t, PKG_FULLNAME_LEN+7);
/* trim file extension (if any) */
- if((p = strstr(tmp, PM_EXT_PKG))) {
+ if((p = strstr(tmp, PKGEXT))) {
*p = '\0';
}
@@ -589,10 +589,10 @@ const char SYMEXPORT *alpm_pkg_get_filename(pmpkg_t *pkg)
_alpm_db_read(pkg->data, pkg, INFRQ_DESC);
}
if(pkg->arch && strlen(pkg->arch) > 0) {
- snprintf(pkg->filename, PKG_FILENAME_LEN, "%s-%s-%s" PM_EXT_PKG,
+ snprintf(pkg->filename, PKG_FILENAME_LEN, "%s-%s-%s" PKGEXT,
pkg->name, pkg->version, pkg->arch);
} else {
- snprintf(pkg->filename, PKG_FILENAME_LEN, "%s-%s" PM_EXT_PKG,
+ snprintf(pkg->filename, PKG_FILENAME_LEN, "%s-%s" PKGEXT,
pkg->name, pkg->version);
}
}
diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c
index 650c594a..af8f5fd7 100644
--- a/lib/libalpm/server.c
+++ b/lib/libalpm/server.c
@@ -196,7 +196,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath,
/* Try to get JUST the name of the package from the filename */
memset(pkgname, 0, PKG_NAME_LEN);
- if((p = strstr(fn, PM_EXT_PKG))) {
+ if((p = strstr(fn, PKGEXT))) {
_alpm_pkg_splitname(fn, pkgname, NULL, 1);
}
if(!strlen(pkgname)) {
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 87f8c720..5b573b72 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -777,7 +777,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
alpm_list_t *i, *j, *files = NULL;
pmtrans_t *tr = NULL;
int replaces = 0, retval = 0;
- char ldir[PATH_MAX];
+ const char *cachedir;
int varcache = 1;
ALPM_LOG_FUNC;
@@ -787,7 +787,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
trans->state = STATE_DOWNLOADING;
/* group sync records by repository and download */
- snprintf(ldir, PATH_MAX, "%s%s", handle->root, handle->cachedir);
+ cachedir = alpm_option_get_cachedir();
for(i = handle->dbs_sync; i; i = i->next) {
pmdb_t *current = i->data;
@@ -806,7 +806,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_PRINTURI, (char *)alpm_db_get_url(current), (char *)fname);
} else {
struct stat buf;
- snprintf(path, PATH_MAX, "%s/%s", ldir, fname);
+ snprintf(path, PATH_MAX, "%s/%s", cachedir, fname);
if(stat(path, &buf)) {
/* file is not in the cache dir, so add it to the list */
files = alpm_list_add(files, strdup(fname));
@@ -820,22 +820,23 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if(files) {
struct stat buf;
EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
- if(stat(ldir, &buf)) {
+ if(stat(cachedir, &buf)) {
/* no cache directory.... try creating it */
- _alpm_log(PM_LOG_WARNING, _("no %s cache exists, creating...\n"), ldir);
- alpm_logaction(_("warning: no %s cache exists, creating..."), ldir);
- if(_alpm_makepath(ldir)) {
+ _alpm_log(PM_LOG_WARNING, _("no %s cache exists, creating...\n"), cachedir);
+ alpm_logaction(_("warning: no %s cache exists, creating..."), cachedir);
+ if(_alpm_makepath(cachedir)) {
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink
* the package afterwards.
*/
_alpm_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n"));
alpm_logaction(_("warning: couldn't create package cache, using /tmp instead"));
- snprintf(ldir, PATH_MAX, "%stmp", alpm_option_get_root());
- alpm_option_set_cachedir(ldir);
+ alpm_option_set_cachedir("/tmp");
+ cachedir = alpm_option_get_cachedir();
varcache = 0;
}
}
- if(_alpm_downloadfiles(current->servers, ldir, files)) {
+ if(_alpm_downloadfiles(current->servers, alpm_option_get_cachedir(),
+ files)) {
_alpm_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"), current->treename);
RET_ERR(PM_ERR_RETRIEVE, -1);
}
@@ -871,7 +872,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
retval = 1;
continue;
}
- snprintf(str, PATH_MAX, "%s%s%s", handle->root, handle->cachedir, pkgname);
+ snprintf(str, PATH_MAX, "%s%s", alpm_option_get_cachedir(), pkgname);
md5sum2 = _alpm_MDFile(str);
sha1sum2 = _alpm_SHAFile(str);
if(md5sum2 == NULL && sha1sum2 == NULL) {
@@ -895,7 +896,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
}
if(doremove) {
char str[PATH_MAX];
- snprintf(str, PATH_MAX, "%s%s%s", handle->root, handle->cachedir, pkgname);
+ snprintf(str, PATH_MAX, "%s%s", alpm_option_get_cachedir(), pkgname);
unlink(str);
snprintf(ptr, 512, _("archive %s was corrupted (bad MD5 or SHA1 checksum)\n"), pkgname);
} else {
@@ -981,7 +982,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
char str[PATH_MAX];
fname = alpm_pkg_get_filename(spkg);
- snprintf(str, PATH_MAX, "%s%s%s", handle->root, handle->cachedir, fname);
+ snprintf(str, PATH_MAX, "%s%s", alpm_option_get_cachedir(), fname);
if(_alpm_trans_addtarget(tr, str) == -1) {
goto error;
}
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index daefa391..39935ab5 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -252,10 +252,11 @@ char *_alpm_strreplace(const char *str, const char *needle, const char *replace)
/* Create a lock file
*/
-int _alpm_lckmk(const char *file)
+int _alpm_lckmk()
{
int fd, count = 0;
char *dir, *ptr;
+ const char *file = alpm_option_get_lockfile();
/* create the dir of the lockfile first */
dir = strdup(file);
@@ -280,8 +281,9 @@ int _alpm_lckmk(const char *file)
/* Remove a lock file
*/
-int _alpm_lckrm(const char *file)
+int _alpm_lckrm()
{
+ const char *file = alpm_option_get_lockfile();
if(unlink(file) == -1 && errno != ENOENT) {
return(-1);
}
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index a1551273..b675da3d 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -49,8 +49,8 @@ int _alpm_copyfile(const char *src, const char *dest);
char *_alpm_strtoupper(char *str);
char *_alpm_strtrim(char *str);
char *_alpm_strreplace(const char *str, const char *needle, const char *replace);
-int _alpm_lckmk(const char *file);
-int _alpm_lckrm(const char *file);
+int _alpm_lckmk();
+int _alpm_lckrm();
int _alpm_unpack(const char *archive, const char *prefix, const char *fn);
int _alpm_rmrf(const char *path);
int _alpm_logaction(unsigned short usesyslog, FILE *f, const char *str);