* 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:
parent
a7d7c96357
commit
cdb46ef3fa
9 changed files with 78 additions and 77 deletions
|
@ -816,7 +816,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
|
||||||
/* run the post-install script if it exists */
|
/* run the post-install script if it exists */
|
||||||
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||||
char pm_install[PATH_MAX];
|
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));
|
alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
|
||||||
if(is_upgrade) {
|
if(is_upgrade) {
|
||||||
_alpm_runscriptlet(handle->root, pm_install, "post_upgrade",
|
_alpm_runscriptlet(handle->root, pm_install, "post_upgrade",
|
||||||
|
|
|
@ -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_log(PM_LOG_DEBUG, _("sync: new mtime for %s: %s"), db->treename, newmtime);
|
||||||
_alpm_db_setlastupdate(db, 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 */
|
/* 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) {
|
for(lp = _alpm_db_get_pkgcache(db); lp; lp = lp->next) {
|
||||||
pmpkg_t *pkg = lp->data;
|
pmpkg_t *pkg = lp->data;
|
||||||
if(pkg && _alpm_db_remove(db, pkg) == -1) {
|
if(pkg && _alpm_db_remove(db, pkg) == -1) {
|
||||||
|
|
|
@ -717,7 +717,7 @@ int _alpm_db_getlastupdate(pmdb_t *db, char *ts)
|
||||||
return(-1);
|
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 */
|
/* get the last update time, if it's there */
|
||||||
if((fp = fopen(file, "r")) == NULL) {
|
if((fp = fopen(file, "r")) == NULL) {
|
||||||
|
@ -749,7 +749,7 @@ int _alpm_db_setlastupdate(pmdb_t *db, char *ts)
|
||||||
return(-1);
|
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) {
|
if((fp = fopen(file, "w")) == NULL) {
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
|
@ -181,7 +181,7 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
|
||||||
/* make sure the database directory exists */
|
/* make sure the database directory exists */
|
||||||
snprintf(path, PATH_MAX, "%s%s/%s", handle->root, handle->dbpath, treename);
|
snprintf(path, PATH_MAX, "%s%s/%s", handle->root, handle->dbpath, treename);
|
||||||
if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
|
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) {
|
if(_alpm_makepath(path) != 0) {
|
||||||
RET_ERR(PM_ERR_SYSTEM, NULL);
|
RET_ERR(PM_ERR_SYSTEM, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,25 +56,25 @@ pmhandle_t *_alpm_handle_new()
|
||||||
#ifndef CYGWIN
|
#ifndef CYGWIN
|
||||||
/* see if we're root or not */
|
/* see if we're root or not */
|
||||||
handle->uid = geteuid();
|
handle->uid = geteuid();
|
||||||
#ifndef FAKEROOT
|
//#ifndef FAKEROOT
|
||||||
if(!handle->uid && getenv("FAKEROOTKEY")) {
|
// if(!handle->uid && getenv("FAKEROOTKEY")) {
|
||||||
/* fakeroot doesn't count, we're non-root */
|
// /* fakeroot doesn't count, we're non-root */
|
||||||
handle->uid = 99;
|
// handle->uid = 99;
|
||||||
}
|
// }
|
||||||
#endif
|
//#endif
|
||||||
|
//
|
||||||
/* see if we're root or not (fakeroot does not count) */
|
// /* see if we're root or not (fakeroot does not count) */
|
||||||
#ifndef FAKEROOT
|
//#ifndef FAKEROOT
|
||||||
if(handle->uid == 0 && !getenv("FAKEROOTKEY")) {
|
// if(handle->uid == 0 && !getenv("FAKEROOTKEY")) {
|
||||||
/* } make vim indent work - stupid ifdef's */
|
// /* } make vim indent work - stupid ifdef's */
|
||||||
#else
|
//#else
|
||||||
if(handle->uid == 0) {
|
// if(handle->uid == 0) {
|
||||||
#endif
|
//#endif
|
||||||
handle->access = PM_ACCESS_RW;
|
// handle->access = PM_ACCESS_RW;
|
||||||
} else {
|
// } else {
|
||||||
handle->access = PM_ACCESS_RO;
|
// handle->access = PM_ACCESS_RO;
|
||||||
}
|
// }
|
||||||
#else
|
//#else
|
||||||
handle->access = PM_ACCESS_RW;
|
handle->access = PM_ACCESS_RW;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -152,16 +152,27 @@ void SYMEXPORT alpm_option_set_logmask(unsigned short mask) { handle->logmask =
|
||||||
void alpm_option_set_root(const char *root)
|
void alpm_option_set_root(const char *root)
|
||||||
{
|
{
|
||||||
if(handle->root) FREE(handle->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 '/' */
|
/* verify root ends in a '/' */
|
||||||
int rootlen = strlen(root);
|
int rootlen = strlen(realroot);
|
||||||
if(root[rootlen-1] != '/') {
|
if(realroot[rootlen-1] != '/') {
|
||||||
rootlen += 1;
|
rootlen += 1;
|
||||||
}
|
}
|
||||||
handle->root = calloc(rootlen+1, sizeof(char));
|
handle->root = calloc(rootlen+1, sizeof(char));
|
||||||
strncpy(handle->root, root, rootlen);
|
strncpy(handle->root, realroot, rootlen);
|
||||||
handle->root[rootlen-1] = '/';
|
handle->root[rootlen-1] = '/';
|
||||||
_alpm_log(PM_LOG_DEBUG, _("option 'root' = %s"), handle->root);
|
_alpm_log(PM_LOG_DEBUG, _("option 'root' = %s"), handle->root);
|
||||||
|
|
||||||
|
free(realroot);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ char* _alpm_MDFile(char *filename)
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
if((file = fopen(filename, "rb")) == NULL) {
|
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 {
|
} else {
|
||||||
char *ret;
|
char *ret;
|
||||||
int i;
|
int i;
|
||||||
|
@ -59,28 +59,16 @@ char* _alpm_MDFile(char *filename)
|
||||||
}
|
}
|
||||||
MDFinal(digest, &context);
|
MDFinal(digest, &context);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
/*printf("MD5 (%s) = ", filename);
|
|
||||||
MDPrint(digest);
|
|
||||||
printf("\n");*/
|
|
||||||
|
|
||||||
ret = (char*)malloc(33);
|
ret = calloc(33, sizeof(char));
|
||||||
ret[0] = '\0';
|
|
||||||
for(i = 0; i < 16; i++) {
|
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(ret);
|
||||||
}
|
}
|
||||||
return(NULL);
|
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: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
|
|
@ -386,35 +386,34 @@ documentation and/or software.
|
||||||
|
|
||||||
|
|
||||||
char* _alpm_SHAFile(char *filename) {
|
char* _alpm_SHAFile(char *filename) {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
struct sha_ctx context;
|
struct sha_ctx context;
|
||||||
int len, i;
|
int len, i;
|
||||||
unsigned char buffer[1024], digest[20];
|
unsigned char buffer[1024], digest[20];
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
if((file = fopen(filename, "rb")) == NULL) {
|
if((file = fopen(filename, "rb")) == NULL) {
|
||||||
fprintf(stderr, _("%s can't be opened\n"), filename);
|
_alpm_log(PM_LOG_ERROR, _("sha1: %s can't be opened\n"), filename);
|
||||||
} else {
|
} else {
|
||||||
sha_init_ctx(&context);
|
sha_init_ctx(&context);
|
||||||
while((len = fread(buffer, 1, 1024, file))) {
|
while((len = fread(buffer, 1, 1024, file))) {
|
||||||
sha_process_bytes(buffer, len, &context);
|
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: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
|
|
@ -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);
|
EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
|
||||||
if(stat(ldir, &buf)) {
|
if(stat(ldir, &buf)) {
|
||||||
/* no cache directory.... try creating it */
|
/* no cache directory.... try creating it */
|
||||||
_alpm_log(PM_LOG_WARNING, _("no %s cache exists. creating...\n"), ldir);
|
_alpm_log(PM_LOG_WARNING, _("no %s cache exists, creating...\n"), ldir);
|
||||||
alpm_logaction(_("warning: no %s cache exists. creating..."), ldir);
|
alpm_logaction(_("warning: no %s cache exists, creating..."), ldir);
|
||||||
if(_alpm_makepath(ldir)) {
|
if(_alpm_makepath(ldir)) {
|
||||||
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink
|
/* couldn't mkdir the cache directory, so fall back to /tmp and unlink
|
||||||
* the package afterwards.
|
* 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;
|
sha1sum1 = spkg->sha1sum;
|
||||||
|
|
||||||
if((md5sum1 == NULL) && (sha1sum1 == NULL)) {
|
if((md5sum1 == NULL) && (sha1sum1 == NULL)) {
|
||||||
|
/* TODO wtf is this? malloc'd strings for error messages? */
|
||||||
if((ptr = (char *)malloc(512)) == NULL) {
|
if((ptr = (char *)malloc(512)) == NULL) {
|
||||||
RET_ERR(PM_ERR_MEMORY, -1);
|
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;
|
retval = 1;
|
||||||
continue;
|
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);
|
md5sum2 = _alpm_MDFile(str);
|
||||||
sha1sum2 = _alpm_SHAFile(str);
|
sha1sum2 = _alpm_SHAFile(str);
|
||||||
if(md5sum2 == NULL && sha1sum2 == NULL) {
|
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) {
|
if(doremove) {
|
||||||
char str[PATH_MAX];
|
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);
|
unlink(str);
|
||||||
snprintf(ptr, 512, _("archive %s was corrupted (bad MD5 or SHA1 checksum)\n"), pkgname);
|
snprintf(ptr, 512, _("archive %s was corrupted (bad MD5 or SHA1 checksum)\n"), pkgname);
|
||||||
} else {
|
} else {
|
||||||
|
@ -957,7 +958,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
||||||
char str[PATH_MAX];
|
char str[PATH_MAX];
|
||||||
|
|
||||||
fname = alpm_pkg_get_filename(spkg);
|
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) {
|
if(_alpm_trans_addtarget(tr, str) == -1) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,8 @@ int _alpm_makepath(const char *path)
|
||||||
if(mkdir(full, 0755)) {
|
if(mkdir(full, 0755)) {
|
||||||
FREE(orig);
|
FREE(orig);
|
||||||
umask(oldmask);
|
umask(oldmask);
|
||||||
|
_alpm_log(PM_LOG_ERROR, _("failed to make path '%s' : %s"),
|
||||||
|
path, strerror(errno));
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue