[pacman-dev] CVS update of pacman-lib/lib/libalpm (9 files)

Aaron Griffin aaron at archlinux.org
Sun Mar 4 04:08:55 EST 2007


    Date: Sunday, March 4, 2007 @ 04:08:55
  Author: aaron
    Path: /home/cvs-pacman/pacman-lib/lib/libalpm

Modified: add.c (1.123 -> 1.124) alpm.c (1.122 -> 1.123)
          be_files.c (1.34 -> 1.35) db.c (1.64 -> 1.65)
          handle.c (1.34 -> 1.35) md5driver.c (1.5 -> 1.6)
          sha1.c (1.4 -> 1.5) sync.c (1.108 -> 1.109) util.c (1.47 -> 1.48)

* 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


-------------+
 add.c       |    2 +-
 alpm.c      |    4 ++--
 be_files.c  |    4 ++--
 db.c        |    2 +-
 handle.c    |   57 ++++++++++++++++++++++++++++++++++-----------------------
 md5driver.c |   20 ++++----------------
 sha1.c      |   51 +++++++++++++++++++++++++--------------------------
 sync.c      |   11 ++++++-----
 util.c      |    2 ++
 9 files changed, 77 insertions(+), 76 deletions(-)


Index: pacman-lib/lib/libalpm/add.c
diff -u pacman-lib/lib/libalpm/add.c:1.123 pacman-lib/lib/libalpm/add.c:1.124
--- pacman-lib/lib/libalpm/add.c:1.123	Sat Mar  3 15:22:48 2007
+++ pacman-lib/lib/libalpm/add.c	Sun Mar  4 04:08:54 2007
@@ -816,7 +816,7 @@
 		/* 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",
Index: pacman-lib/lib/libalpm/alpm.c
diff -u pacman-lib/lib/libalpm/alpm.c:1.122 pacman-lib/lib/libalpm/alpm.c:1.123
--- pacman-lib/lib/libalpm/alpm.c:1.122	Sat Mar  3 03:13:59 2007
+++ pacman-lib/lib/libalpm/alpm.c	Sun Mar  4 04:08:54 2007
@@ -299,10 +299,10 @@
 			_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) {
Index: pacman-lib/lib/libalpm/be_files.c
diff -u pacman-lib/lib/libalpm/be_files.c:1.34 pacman-lib/lib/libalpm/be_files.c:1.35
--- pacman-lib/lib/libalpm/be_files.c:1.34	Sun Mar  4 01:28:48 2007
+++ pacman-lib/lib/libalpm/be_files.c	Sun Mar  4 04:08:54 2007
@@ -717,7 +717,7 @@
 		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 @@
 		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);
Index: pacman-lib/lib/libalpm/db.c
diff -u pacman-lib/lib/libalpm/db.c:1.64 pacman-lib/lib/libalpm/db.c:1.65
--- pacman-lib/lib/libalpm/db.c:1.64	Sat Mar  3 03:13:59 2007
+++ pacman-lib/lib/libalpm/db.c	Sun Mar  4 04:08:54 2007
@@ -181,7 +181,7 @@
 	/* 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);
 		}
Index: pacman-lib/lib/libalpm/handle.c
diff -u pacman-lib/lib/libalpm/handle.c:1.34 pacman-lib/lib/libalpm/handle.c:1.35
--- pacman-lib/lib/libalpm/handle.c:1.34	Sun Mar  4 01:28:48 2007
+++ pacman-lib/lib/libalpm/handle.c	Sun Mar  4 04:08:55 2007
@@ -56,25 +56,25 @@
 #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 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);
 	}
 }
 
Index: pacman-lib/lib/libalpm/md5driver.c
diff -u pacman-lib/lib/libalpm/md5driver.c:1.5 pacman-lib/lib/libalpm/md5driver.c:1.6
--- pacman-lib/lib/libalpm/md5driver.c:1.5	Tue Jan 30 03:14:11 2007
+++ pacman-lib/lib/libalpm/md5driver.c	Sun Mar  4 04:08:55 2007
@@ -48,7 +48,7 @@
 	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 @@
 		}
 		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: */
Index: pacman-lib/lib/libalpm/sha1.c
diff -u pacman-lib/lib/libalpm/sha1.c:1.4 pacman-lib/lib/libalpm/sha1.c:1.5
--- pacman-lib/lib/libalpm/sha1.c:1.4	Tue Jan 30 03:14:11 2007
+++ pacman-lib/lib/libalpm/sha1.c	Sun Mar  4 04:08:55 2007
@@ -386,35 +386,34 @@
 
 
 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;
+	FILE *file;
+	struct sha_ctx context;
+	int len, i;
+	unsigned char buffer[1024], digest[20];
+	char *ret;
 
-    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);
-	}
-	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]);
+	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);
 	}
-	return(ret);
-    }
 
-    return(NULL);
+	return(NULL);
 }
 
 /* vim: set ts=2 sw=2 noet: */
Index: pacman-lib/lib/libalpm/sync.c
diff -u pacman-lib/lib/libalpm/sync.c:1.108 pacman-lib/lib/libalpm/sync.c:1.109
--- pacman-lib/lib/libalpm/sync.c:1.108	Sat Mar  3 20:22:57 2007
+++ pacman-lib/lib/libalpm/sync.c	Sun Mar  4 04:08:55 2007
@@ -800,8 +800,8 @@
 			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 @@
 		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 @@
 			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 @@
 			}
 			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 @@
 		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;
 		}
Index: pacman-lib/lib/libalpm/util.c
diff -u pacman-lib/lib/libalpm/util.c:1.47 pacman-lib/lib/libalpm/util.c:1.48
--- pacman-lib/lib/libalpm/util.c:1.47	Sat Mar  3 03:14:00 2007
+++ pacman-lib/lib/libalpm/util.c	Sun Mar  4 04:08:55 2007
@@ -139,6 +139,8 @@
 				if(mkdir(full, 0755)) {
 					FREE(orig);
 					umask(oldmask);
+					_alpm_log(PM_LOG_ERROR, _("failed to make path '%s' : %s"),
+										path, strerror(errno));
 					return(1);
 				}
 			}




More information about the pacman-dev mailing list