summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-03-04 09:08:54 +0000
committerAaron Griffin <aaron@archlinux.org>2007-03-04 09:08:54 +0000
commitcdb46ef3fa6d2bea95ae45b8b807497982b18fd5 (patch)
tree0f2340ed62be9f99f1e4bf0764c65aad1e701964 /lib
parenta7d7c963579176dfefe424931a57e86bc8b51924 (diff)
downloadpacman-cdb46ef3fa6d2bea95ae45b8b807497982b18fd5.tar.xz
* Fixed a whole mess of extra '/' pathing issues when a different root is
specified * Use db->path when appropriate * Commented out the FAKEROOT checks in libalpm. This should never ever be done. TODO test this quite a bit, as this will never cause the transactions to fail if RW operations are requested... right now it is totally up to the front end to decide when to fail * Use realpath() to canonicalize the root path when specified, so _alpm_makepath() doesn't freak out * Fixed some output/indent of MDFile and SHAFile algorithms * More efficient sprintf() usage in MDFile/SHAFile * Added real error output to _alpm_makepath
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/add.c2
-rw-r--r--lib/libalpm/alpm.c4
-rw-r--r--lib/libalpm/be_files.c4
-rw-r--r--lib/libalpm/db.c2
-rw-r--r--lib/libalpm/handle.c57
-rw-r--r--lib/libalpm/md5driver.c20
-rw-r--r--lib/libalpm/sha1.c53
-rw-r--r--lib/libalpm/sync.c11
-rw-r--r--lib/libalpm/util.c2
9 files changed, 78 insertions, 77 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index a5fc6fb9..97d1ea72 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -816,7 +816,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* run the post-install script if it exists */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
char pm_install[PATH_MAX];
- snprintf(pm_install, PATH_MAX, "%s%s/%s/%s-%s/install", handle->root, handle->dbpath, db->treename,
+ snprintf(pm_install, PATH_MAX, "%s%s%s-%s/install", handle->root, db->path,
alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
if(is_upgrade) {
_alpm_runscriptlet(handle->root, pm_install, "post_upgrade",
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 96ad3416..733a4360 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -299,10 +299,10 @@ 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%s" PM_EXT_DB, handle->root, handle->dbpath, db->treename);
/* remove the old dir */
- _alpm_log(PM_LOG_DEBUG, _("flushing database %s%s"), handle->dbpath, db->treename);
+ _alpm_log(PM_LOG_DEBUG, _("flushing database %s%s"), db->path);
for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
pmpkg_t *pkg = lp->data;
if(pkg && _alpm_db_remove(db, pkg) == -1) {
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 43d7a711..f8e73fbb 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -717,7 +717,7 @@ int _alpm_db_getlastupdate(pmdb_t *db, char *ts)
return(-1);
}
- snprintf(file, PATH_MAX, "%s%s/%s/.lastupdate", handle->root, handle->dbpath, db->treename);
+ snprintf(file, PATH_MAX, "%s%s.lastupdate", handle->root, db->path);
/* get the last update time, if it's there */
if((fp = fopen(file, "r")) == NULL) {
@@ -749,7 +749,7 @@ int _alpm_db_setlastupdate(pmdb_t *db, char *ts)
return(-1);
}
- snprintf(file, PATH_MAX, "%s%s/%s/.lastupdate", handle->root, handle->dbpath, db->treename);
+ snprintf(file, PATH_MAX, "%s%s.lastupdate", handle->root, db->path);
if((fp = fopen(file, "w")) == NULL) {
return(-1);
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index ab828614..a6ef0528 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -181,7 +181,7 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
/* make sure the database directory exists */
snprintf(path, PATH_MAX, "%s%s/%s", handle->root, handle->dbpath, treename);
if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
- _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist -- try creating it"), path);
+ _alpm_log(PM_LOG_ERROR, _("database directory '%s' does not exist, try creating it"), path);
if(_alpm_makepath(path) != 0) {
RET_ERR(PM_ERR_SYSTEM, NULL);
}
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 5ca8258e..c17d86a5 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -56,25 +56,25 @@ pmhandle_t *_alpm_handle_new()
#ifndef CYGWIN
/* see if we're root or not */
handle->uid = geteuid();
-#ifndef FAKEROOT
- if(!handle->uid && getenv("FAKEROOTKEY")) {
- /* fakeroot doesn't count, we're non-root */
- handle->uid = 99;
- }
-#endif
-
- /* see if we're root or not (fakeroot does not count) */
-#ifndef FAKEROOT
- if(handle->uid == 0 && !getenv("FAKEROOTKEY")) {
- /* } make vim indent work - stupid ifdef's */
-#else
- if(handle->uid == 0) {
-#endif
- handle->access = PM_ACCESS_RW;
- } else {
- handle->access = PM_ACCESS_RO;
- }
-#else
+//#ifndef FAKEROOT
+// if(!handle->uid && getenv("FAKEROOTKEY")) {
+// /* fakeroot doesn't count, we're non-root */
+// handle->uid = 99;
+// }
+//#endif
+//
+// /* see if we're root or not (fakeroot does not count) */
+//#ifndef FAKEROOT
+// if(handle->uid == 0 && !getenv("FAKEROOTKEY")) {
+// /* } make vim indent work - stupid ifdef's */
+//#else
+// if(handle->uid == 0) {
+//#endif
+// handle->access = PM_ACCESS_RW;
+// } else {
+// handle->access = PM_ACCESS_RO;
+// }
+//#else
handle->access = PM_ACCESS_RW;
#endif
@@ -152,16 +152,27 @@ void SYMEXPORT alpm_option_set_logmask(unsigned short mask) { handle->logmask =
void alpm_option_set_root(const char *root)
{
if(handle->root) FREE(handle->root);
- if(root) {
+ /* According to the man page, realpath is safe to use IFF the second arg is
+ * NULL. */
+ char *realroot = realpath(root, NULL);
+ if(!realroot) {
+ realroot = root;
+ _alpm_log(PM_LOG_ERROR, _("cannot canonicalize specified root path '%s'"), root);
+ }
+
+ /* check again, in case both are null */
+ if(realroot) {
/* verify root ends in a '/' */
- int rootlen = strlen(root);
- if(root[rootlen-1] != '/') {
+ int rootlen = strlen(realroot);
+ if(realroot[rootlen-1] != '/') {
rootlen += 1;
}
handle->root = calloc(rootlen+1, sizeof(char));
- strncpy(handle->root, root, rootlen);
+ strncpy(handle->root, realroot, rootlen);
handle->root[rootlen-1] = '/';
_alpm_log(PM_LOG_DEBUG, _("option 'root' = %s"), handle->root);
+
+ free(realroot);
}
}
diff --git a/lib/libalpm/md5driver.c b/lib/libalpm/md5driver.c
index 2effa5f7..968caed8 100644
--- a/lib/libalpm/md5driver.c
+++ b/lib/libalpm/md5driver.c
@@ -48,7 +48,7 @@ char* _alpm_MDFile(char *filename)
ALPM_LOG_FUNC;
if((file = fopen(filename, "rb")) == NULL) {
- printf (_("%s can't be opened\n"), filename);
+ _alpm_log(PM_LOG_ERROR, _("%s can't be opened\n"), filename);
} else {
char *ret;
int i;
@@ -59,28 +59,16 @@ char* _alpm_MDFile(char *filename)
}
MDFinal(digest, &context);
fclose(file);
- /*printf("MD5 (%s) = ", filename);
- MDPrint(digest);
- printf("\n");*/
- ret = (char*)malloc(33);
- ret[0] = '\0';
+ ret = calloc(33, sizeof(char));
for(i = 0; i < 16; i++) {
- sprintf(ret, "%s%02x", ret, digest[i]);
+ sprintf(ret+(i*2), "%02x", digest[i]);
}
+ _alpm_log(PM_LOG_DEBUG, _("sha1(%s) = %s"), filename, ret);
return(ret);
}
return(NULL);
}
-/* Prints a message digest in hexadecimal.
- */
-void _alpm_MDPrint(unsigned char digest[16])
-{
- unsigned int i;
- for (i = 0; i < 16; i++)
- printf ("%02x", digest[i]);
-}
-
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/sha1.c b/lib/libalpm/sha1.c
index cf1831ea..956e87a9 100644
--- a/lib/libalpm/sha1.c
+++ b/lib/libalpm/sha1.c
@@ -386,35 +386,34 @@ documentation and/or software.
char* _alpm_SHAFile(char *filename) {
- FILE *file;
- struct sha_ctx context;
- int len, i;
- unsigned char buffer[1024], digest[20];
- char *ret;
-
- ALPM_LOG_FUNC;
-
- if((file = fopen(filename, "rb")) == NULL) {
- fprintf(stderr, _("%s can't be opened\n"), filename);
- } else {
- sha_init_ctx(&context);
- while((len = fread(buffer, 1, 1024, file))) {
- sha_process_bytes(buffer, len, &context);
+ FILE *file;
+ struct sha_ctx context;
+ int len, i;
+ unsigned char buffer[1024], digest[20];
+ char *ret;
+
+ ALPM_LOG_FUNC;
+
+ if((file = fopen(filename, "rb")) == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("sha1: %s can't be opened\n"), filename);
+ } else {
+ sha_init_ctx(&context);
+ while((len = fread(buffer, 1, 1024, file))) {
+ sha_process_bytes(buffer, len, &context);
+ }
+ sha_finish_ctx(&context, digest);
+ fclose(file);
+
+ ret = (char*)malloc(41);
+ ret[0] = '\0';
+ for(i = 0; i < 20; i++) {
+ sprintf(ret+(i*2), "%02x", digest[i]);
+ }
+ _alpm_log(PM_LOG_DEBUG, _("sha1(%s) = %s"), filename, ret);
+ return(ret);
}
- sha_finish_ctx(&context, digest);
- fclose(file);
-#ifdef DEBUG
- SHAPrint(digest);
-#endif
- ret = (char*)malloc(41);
- ret[0] = '\0';
- for(i = 0; i < 20; i++) {
- sprintf(ret, "%s%02x", ret, digest[i]);
- }
- return(ret);
- }
- return(NULL);
+ return(NULL);
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 71925482..337e350a 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -800,8 +800,8 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
if(stat(ldir, &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);
+ _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)) {
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink
* the package afterwards.
@@ -840,6 +840,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
sha1sum1 = spkg->sha1sum;
if((md5sum1 == NULL) && (sha1sum1 == NULL)) {
+ /* TODO wtf is this? malloc'd strings for error messages? */
if((ptr = (char *)malloc(512)) == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
@@ -848,7 +849,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%s", handle->root, handle->cachedir, pkgname);
md5sum2 = _alpm_MDFile(str);
sha1sum2 = _alpm_SHAFile(str);
if(md5sum2 == NULL && sha1sum2 == NULL) {
@@ -872,7 +873,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%s", handle->root, handle->cachedir, pkgname);
unlink(str);
snprintf(ptr, 512, _("archive %s was corrupted (bad MD5 or SHA1 checksum)\n"), pkgname);
} else {
@@ -957,7 +958,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%s", handle->root, handle->cachedir, fname);
if(_alpm_trans_addtarget(tr, str) == -1) {
goto error;
}
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index dd1ba812..c526ed8e 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -139,6 +139,8 @@ int _alpm_makepath(const char *path)
if(mkdir(full, 0755)) {
FREE(orig);
umask(oldmask);
+ _alpm_log(PM_LOG_ERROR, _("failed to make path '%s' : %s"),
+ path, strerror(errno));
return(1);
}
}