1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

* 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
This commit is contained in:
Aaron Griffin 2007-03-04 09:08:54 +00:00
parent a7d7c96357
commit cdb46ef3fa
9 changed files with 78 additions and 77 deletions

View File

@ -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",

View File

@ -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) {

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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: */

View File

@ -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;
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]);
}
return(ret);
}
ALPM_LOG_FUNC;
return(NULL);
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(NULL);
}
/* vim: set ts=2 sw=2 noet: */

View File

@ -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;
}

View File

@ -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);
}
}