index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
-rw-r--r-- | configure.ac | 62 | ||||
-rw-r--r-- | lib/libalpm/Makefile.am | 12 | ||||
-rw-r--r-- | lib/libalpm/alpm.c | 30 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 3 | ||||
-rw-r--r-- | lib/libalpm/db.c | 18 | ||||
-rw-r--r-- | lib/libalpm/db.h | 2 | ||||
-rw-r--r-- | lib/libalpm/handle.c | 19 | ||||
-rw-r--r-- | lib/libalpm/handle.h | 1 | ||||
-rw-r--r-- | lib/libalpm/md5driver.c | 2 | ||||
-rw-r--r-- | lib/libalpm/package.c | 6 | ||||
-rw-r--r-- | lib/libalpm/server.c | 2 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 27 | ||||
-rw-r--r-- | lib/libalpm/util.c | 6 | ||||
-rw-r--r-- | lib/libalpm/util.h | 4 | ||||
-rwxr-xr-x | pactest/pmtest.py | 9 | ||||
-rwxr-xr-x | pactest/util.py | 2 | ||||
-rw-r--r-- | src/pacman/Makefile.am | 10 | ||||
-rw-r--r-- | src/pacman/add.c | 3 | ||||
-rw-r--r-- | src/pacman/callback.c | 2 | ||||
-rw-r--r-- | src/pacman/pacman.c | 20 | ||||
-rw-r--r-- | src/pacman/query.c | 5 | ||||
-rw-r--r-- | src/pacman/remove.c | 3 | ||||
-rw-r--r-- | src/pacman/sync.c | 29 | ||||
-rw-r--r-- | src/pacman/util.c | 4 | ||||
-rw-r--r-- | src/pacman/util.h | 4 |
diff --git a/configure.ac b/configure.ac index 0bed9256..834d6191 100644 --- a/configure.ac +++ b/configure.ac @@ -33,26 +33,6 @@ AC_ARG_WITH(root-dir, AC_HELP_STRING([--with-root-dir=path], [Set the location of pacman's root operating directory]), [ROOTDIR=$withval], [ROOTDIR=/]) -# Help line for database path -AC_ARG_WITH(db-path, - AC_HELP_STRING([--with-db-path=path], [Set the location of pacman's database]), - [DBPATH=$withval], [DBPATH=var/lib/pacman/]) - -# Help line for cache directory -AC_ARG_WITH(cache-dir, - AC_HELP_STRING([--with-cache-dir=path], [Set the location of pacman's cache directory]), - [CACHEDIR=$withval], [CACHEDIR=var/cache/pacman/pkg/]) - -# Help line for lock file -AC_ARG_WITH(lock-file, - AC_HELP_STRING([--with-lock-file=path], [Set the location of pacman's lock file]), - [LOCKFILE=$withval], [LOCKFILE=var/run/pacman.lck]) - -# Help line for config file -AC_ARG_WITH(config-file, - AC_HELP_STRING([--with-config-file=path], [Set the location of pacman's config file]), - [CONFIGFILE=$withval], [CONFIGFILE=etc/pacman.conf]) - # Help line for package extension AC_ARG_WITH(pkg-ext, AC_HELP_STRING([--with-pkg-ext=ext], [Set the file extension used by packages]), @@ -209,32 +189,12 @@ else fi # Set root directory -AC_DEFINE_UNQUOTED([PM_ROOT], "$ROOTDIR", [Location of pacman's default root directory]) -AC_SUBST(ROOTDIR) - -# Set database path -AC_DEFINE_UNQUOTED([PM_DBPATH], "$DBPATH", [Location of pacman database]) -AC_SUBST(DBPATH) - -# Set cache directory -AC_DEFINE_UNQUOTED([PM_CACHEDIR], "$CACHEDIR", [Location of pacman's package cache]) -AC_SUBST(CACHEDIR) - -# Set lock file location -AC_DEFINE_UNQUOTED([PM_LOCK], "$LOCKFILE", [Location of pacman lock file]) -AC_SUBST(LOCKFILE) - -# Set configuration file location -AC_DEFINE_UNQUOTED([PM_CONF], "$CONFIGFILE", [Location of pacman configuration file]) -AC_SUBST(CONFIGFILE) - +AC_DEFINE_UNQUOTED([ROOTDIR], "$ROOTDIR", [Location of pacman's default root di +rectory]) # Set package file extension -AC_DEFINE_UNQUOTED([PM_EXT_PKG], "$PKGEXT", [The file extension used by pacman packages]) -AC_SUBST(PKGEXT) - +AC_DEFINE_UNQUOTED([PKGEXT], "$PKGEXT", [The file extension used by pacman packages]) # Set database file extension -AC_DEFINE_UNQUOTED([PM_EXT_DB], "$DBEXT", [The file extension used by pacman databases]) -AC_SUBST(DBEXT) +AC_DEFINE_UNQUOTED([DBEXT], "$DBEXT", [The file extension used by pacman databases]) # Configuration files AC_CONFIG_FILES([ @@ -257,9 +217,15 @@ AC_OUTPUT echo " $PACKAGE_STRING: + Build information: + source code location : ${srcdir} prefix : ${prefix} sysconfdir : $(eval echo ${sysconfdir}) - source code location : ${srcdir} + conf file : $(eval echo ${sysconfdir})/pacman.conf + localstatedir : $(eval echo ${localstatedir}) + lock file : $(eval echo ${localstatedir})/run/pacman.lck + database dir : $(eval echo ${localstatedir})/lib/pacman/ + cache dir : $(eval echo ${localstatedir})/cache/pacman/pkg/ compiler : ${CC} compiler flags : ${CFLAGS} defines : ${DEFS} @@ -272,11 +238,7 @@ $PACKAGE_STRING: pacman version : ${PACKAGE_VERSION} Directory and file information: - root directory : ${ROOTDIR} - database path : ${ROOTDIR}${DBPATH} - cache directory : ${ROOTDIR}${CACHEDIR} - lock file location : ${ROOTDIR}${LOCKFILE} - conf file location : ${ROOTDIR}${CONFIGFILE} + root working directory : ${ROOTDIR} package extension : ${PKGEXT} database extension : ${DBEXT} 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); diff --git a/pactest/pmtest.py b/pactest/pmtest.py index 06b65bbb..dd524211 100755 --- a/pactest/pmtest.py +++ b/pactest/pmtest.py @@ -192,8 +192,13 @@ class pmtest: cmd.append("libtool gdb --args") if pacman["valgrind"]: cmd.append("valgrind --tool=memcheck --leak-check=full --show-reachable=yes") - cmd.append("%s --config=%s --root=%s" \ - % (pacman["bin"], os.path.join(self.root, PACCONF), self.root)) + cmd.append("%s --config=%s --root=%s --dbpath=%s --cachedir=%s --lock=%s" \ + % (pacman["bin"], + os.path.join(self.root, PACCONF), + self.root, + os.path.join(self.root, PM_DBPATH), + os.path.join(self.root, PM_CACHEDIR), + os.path.join(self.root, PM_LOCK) )) if not pacman["manual-confirm"]: cmd.append("--noconfirm") if pacman["debug"]: diff --git a/pactest/util.py b/pactest/util.py index 574a59be..98c22a5c 100755 --- a/pactest/util.py +++ b/pactest/util.py @@ -28,7 +28,7 @@ import stat PM_ROOT = "/" PM_DBPATH = "var/lib/pacman" PM_CACHEDIR = "var/cache/pacman/pkg" -PM_LOCK = "/tmp/pacman.lck" +PM_LOCK = "var/run/pacman.lck" PM_EXT_PKG = ".pkg.tar.gz" PM_EXT_DB = ".db.tar.gz" PM_PACNEW = ".pacnew" diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am index 06d1b447..5248abf3 100644 --- a/src/pacman/Makefile.am +++ b/src/pacman/Makefile.am @@ -1,9 +1,15 @@ SUBDIRS = po +# paths set at make time +conffile = ${sysconfdir}/pacman.conf +lockfile = ${localstatedir}/run/pacman.lck + bin_PROGRAMS = pacman pacman.static -localedir = $(datadir)/locale -DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ +DEFS = -DLOCALEDIR=\"@localedir@\" \ + -DCONFFILE=\"$(conffile)\" \ + -DLOCKFILE=\"$(lockfile)\" \ + @DEFS@ INCLUDES = -I$(top_srcdir)/lib/libalpm AM_CFLAGS = -pedantic -D_GNU_SOURCE diff --git a/src/pacman/add.c b/src/pacman/add.c index cf636234..ef84a398 100644 --- a/src/pacman/add.c +++ b/src/pacman/add.c @@ -95,8 +95,7 @@ int pacman_add(alpm_list_t *targets) if(pm_errno == PM_ERR_HANDLE_LOCK) { /* TODO this and the 2 other places should probably be on stderr */ printf(_(" if you're sure a package manager is not already\n" - " running, you can remove %s%s.\n"), - alpm_option_get_root(), PM_LOCK); + " running, you can remove %s.\n"), LOCKFILE); } return(1); } diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 5f391306..e13a7e7d 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -550,7 +550,7 @@ void cb_dl_progress(const char *filename, int xfered, int total) fname = strdup(filename); /* strip extension if it's there * NOTE: in the case of package files, only the pkgname is sent now */ - if((p = strstr(fname, PM_EXT_PKG)) || (p = strstr(fname, PM_EXT_DB))) { + if((p = strstr(fname, PKGEXT)) || (p = strstr(fname, DBEXT))) { *p = '\0'; } if(strlen(fname) > FILENAME_TRIM_LEN) { diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 58e85b22..e3656830 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -159,6 +159,7 @@ static void usage(int op, char *myname) printf(_(" -r, --root <path> set an alternate installation root\n")); printf(_(" -b, --dbpath <path> set an alternate database location\n")); printf(_(" --cachedir <dir> set an alternate package cache location\n")); + printf(_(" --lock <file> set an alternate lockfile location\n")); } } @@ -302,6 +303,7 @@ static int parseargs(int argc, char *argv[]) {"noscriptlet", no_argument, 0, 1005}, {"ask", required_argument, 0, 1006}, {"cachedir", required_argument, 0, 1007}, + {"lock", required_argument, 0, 1008}, {0, 0, 0, 0} }; struct stat st; @@ -360,6 +362,9 @@ static int parseargs(int argc, char *argv[]) } alpm_option_set_cachedir(optarg); break; + case 1008: + alpm_option_set_lockfile(optarg); + break; case 'A': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_ADD); break; case 'F': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_UPGRADE); @@ -519,7 +524,7 @@ int main(int argc, char *argv[]) (config->op_s_search || config->group || config->op_q_list || config->op_q_info || config->flags & PM_TRANS_FLAG_PRINTURIS)) || (config->op == PM_OP_DEPTEST && config->op_d_resolve) - || (strcmp(alpm_option_get_root(), PM_ROOT) != 0)) { + || (strcmp(alpm_option_get_root(), ROOTDIR) != 0)) { /* special case: PM_OP_SYNC can be used w/ config->op_s_search by any user */ /* special case: ignore root user check if -r is specified, fall back on * normal FS checking */ @@ -535,7 +540,7 @@ int main(int argc, char *argv[]) alpm_option_set_logcb(cb_log); if(config->configfile == NULL) { - config->configfile = strdup(PM_ROOT PM_CONF); + config->configfile = strdup(CONFFILE); } if(alpm_parse_config(config->configfile, NULL, "") != 0) { @@ -548,10 +553,13 @@ int main(int argc, char *argv[]) alpm_option_set_dlcb(cb_dl_progress); if(config->verbose > 0) { - printf("Root : %s\n", alpm_option_get_root()); - printf("DBPath : %s\n", alpm_option_get_dbpath()); - printf("CacheDir : %s\n", alpm_option_get_cachedir()); - list_display(_("Targets :"), pm_targets); + printf("Root : %s\n", alpm_option_get_root()); + printf("Conf File : %s\n", config->configfile); + printf("Lock File : %s\n", alpm_option_get_lockfile()); + printf("Root : %s\n", alpm_option_get_root()); + printf("DBPath : %s\n", alpm_option_get_dbpath()); + printf("CacheDir : %s\n", alpm_option_get_cachedir()); + list_display("Targets :", pm_targets); } /* Opening local database */ diff --git a/src/pacman/query.c b/src/pacman/query.c index 57850e8f..a4a42075 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -311,8 +311,9 @@ int pacman_query(alpm_list_t *targets) } if(config->op_q_changelog) { char changelog[PATH_MAX]; - snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog", - alpm_option_get_root(), alpm_option_get_dbpath(), + /* TODO should be done in the backend- no raw DB stuff up front */ + snprintf(changelog, PATH_MAX, "%s/%s/%s-%s/changelog", + alpm_option_get_dbpath(), alpm_db_get_name(db_local), alpm_pkg_get_name(info), alpm_pkg_get_version(info)); diff --git a/src/pacman/remove.c b/src/pacman/remove.c index e4f34886..9cdfb0d8 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -86,8 +86,7 @@ int pacman_remove(alpm_list_t *targets) alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { printf(_(" if you're sure a package manager is not already\n" - " running, you can remove %s%s.\n"), - alpm_option_get_root(), PM_LOCK); + " running, you can remove %s.\n"), LOCKFILE); } FREELIST(finaltargs); return(1); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index f013d45f..d04c7da9 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -61,7 +61,7 @@ static int split_pkgname(char *target, char *name, char *version) } strncpy(tmp, p, 512); /* trim file extension (if any) */ - if((p = strstr(tmp, PM_EXT_PKG))) { + if((p = strstr(tmp, PKGEXT))) { *p = '\0'; } /* trim architecture */ @@ -89,13 +89,7 @@ static int split_pkgname(char *target, char *name, char *version) static int sync_cleancache(int level) { - const char *root, *cachedir; - char dirpath[PATH_MAX]; - - root = alpm_option_get_root(); - cachedir = alpm_option_get_cachedir(); - - snprintf(dirpath, PATH_MAX, "%s%s", root, cachedir); + const char *cachedir = alpm_option_get_cachedir(); if(level == 1) { /* incomplete cleanup: we keep latest packages and partial downloads */ @@ -106,7 +100,7 @@ static int sync_cleancache(int level) if(!yesno(_("Do you want to remove old packages from cache? [Y/n] "))) return(0); printf(_("removing old packages from cache... ")); - dir = opendir(dirpath); + dir = opendir(cachedir); if(dir == NULL) { fprintf(stderr, _("error: could not access cache directory\n")); return(1); @@ -124,12 +118,12 @@ static int sync_cleancache(int level) char *str = alpm_list_getdata(i); char name[256], version[64]; - if(strstr(str, PM_EXT_PKG) == NULL) { + if(strstr(str, PKGEXT) == NULL) { clean = alpm_list_add(clean, strdup(str)); continue; } /* we keep partially downloaded files */ - if(strstr(str, PM_EXT_PKG ".part")) { + if(strstr(str, PKGEXT ".part")) { continue; } if(split_pkgname(str, name, version) != 0) { @@ -140,10 +134,10 @@ static int sync_cleancache(int level) char *s = alpm_list_getdata(j); char n[256], v[64]; - if(strstr(s, PM_EXT_PKG) == NULL) { + if(strstr(s, PKGEXT) == NULL) { continue; } - if(strstr(s, PM_EXT_PKG ".part")) { + if(strstr(s, PKGEXT ".part")) { continue; } if(split_pkgname(s, n, v) != 0) { @@ -163,7 +157,7 @@ static int sync_cleancache(int level) for(i = clean; i; i = alpm_list_next(i)) { char path[PATH_MAX]; - snprintf(path, PATH_MAX, "%s/%s", dirpath, (char *)alpm_list_getdata(i)); + snprintf(path, PATH_MAX, "%s/%s", cachedir, (char *)alpm_list_getdata(i)); unlink(path); } FREELIST(clean); @@ -173,12 +167,12 @@ static int sync_cleancache(int level) return(0); printf(_("removing all packages from cache... ")); - if(rmrf(dirpath)) { + if(rmrf(cachedir)) { fprintf(stderr, _("error: could not remove cache directory\n")); return(1); } - if(makepath(dirpath)) { + if(makepath(cachedir)) { fprintf(stderr, _("error: could not create new cache directory\n")); return(1); } @@ -492,8 +486,7 @@ int pacman_sync(alpm_list_t *targets) alpm_strerror(pm_errno)); if(pm_errno == PM_ERR_HANDLE_LOCK) { printf(_(" if you're sure a package manager is not already\n" - " running, you can remove %s%s.\n"), - alpm_option_get_root(), PM_LOCK); + " running, you can remove %s.\n"), LOCKFILE); } return(1); } diff --git a/src/pacman/util.c b/src/pacman/util.c index f38be60c..e48ea10f 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -80,7 +80,7 @@ int getcols() } /* does the same thing as 'mkdir -p' */ -int makepath(char *path) +int makepath(const char *path) { char *orig, *str, *ptr; char full[PATH_MAX+1] = ""; @@ -112,7 +112,7 @@ int makepath(char *path) } /* does the same thing as 'rm -rf' */ -int rmrf(char *path) +int rmrf(const char *path) { int errflag = 0; struct dirent *dp; diff --git a/src/pacman/util.h b/src/pacman/util.h index 45c8b07d..755b30e1 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -38,8 +38,8 @@ #endif int getcols(); -int makepath(char *path); -int rmrf(char *path); +int makepath(const char *path); +int rmrf(const char *path); void indentprint(const char *str, int indent); char *strtoupper(char *str); char *strtrim(char *str); |