mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
put back treename in db->path
This commit is contained in:
parent
80c7f0efca
commit
ad2c7463c9
@ -164,6 +164,7 @@ pmdb_t *alpm_db_register(char *treename)
|
||||
struct stat buf;
|
||||
pmdb_t *db;
|
||||
int found = 0;
|
||||
char path[PATH_MAX];
|
||||
|
||||
/* Sanity checks */
|
||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, NULL));
|
||||
@ -190,18 +191,20 @@ pmdb_t *alpm_db_register(char *treename)
|
||||
|
||||
_alpm_log(PM_LOG_FLOW1, "registering database '%s'", treename);
|
||||
|
||||
/* 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_FLOW1, "database directory '%s' does not exist -- try creating it", path);
|
||||
if(_alpm_makepath(path) != 0) {
|
||||
RET_ERR(PM_ERR_SYSTEM, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
db = _alpm_db_new(handle->root, handle->dbpath, treename);
|
||||
if(db == NULL) {
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* make sure the database directory exists */
|
||||
if(stat(db->path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
|
||||
if(_alpm_makepath(db->path) != 0) {
|
||||
RET_ERR(PM_ERR_SYSTEM, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
_alpm_log(PM_LOG_DEBUG, "opening database '%s'", db->treename);
|
||||
if(_alpm_db_open(db, DB_O_CREATE) == -1) {
|
||||
_alpm_db_free(db);
|
||||
|
@ -38,26 +38,13 @@
|
||||
|
||||
int _alpm_db_open(pmdb_t *db, int mode)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
|
||||
if(db == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
snprintf(path, PATH_MAX, "%s/%s", db->path, db->treename);
|
||||
|
||||
db->handle = opendir(path);
|
||||
db->handle = opendir(db->path);
|
||||
if(db->handle == NULL) {
|
||||
if(mode & DB_O_CREATE) {
|
||||
_alpm_log(PM_LOG_WARNING, "could not open database '%s' -- try creating it", db->treename);
|
||||
_alpm_log(PM_LOG_DEBUG, "creating database '%s'", db->treename);
|
||||
if(mkdir(path, 0755) == 0) {
|
||||
db->handle = opendir(path);
|
||||
}
|
||||
}
|
||||
if(!(mode & DB_O_CREATE) || db->handle == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
|
||||
return(0);
|
||||
@ -106,7 +93,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, unsigned int inforeq)
|
||||
continue;
|
||||
}
|
||||
/* stat the entry, make sure it's a directory */
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s", db->path, db->treename, ent->d_name);
|
||||
snprintf(path, PATH_MAX, "%s/%s", db->path, ent->d_name);
|
||||
if(stat(path, &sbuf) || !S_ISDIR(sbuf.st_mode)) {
|
||||
continue;
|
||||
}
|
||||
@ -139,7 +126,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, unsigned int inforeq)
|
||||
continue;
|
||||
}
|
||||
/* stat the entry, make sure it's a directory */
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s", db->path, db->treename, ent->d_name);
|
||||
snprintf(path, PATH_MAX, "%s/%s", db->path, ent->d_name);
|
||||
if(!stat(path, &sbuf) && S_ISDIR(sbuf.st_mode)) {
|
||||
isdir = 1;
|
||||
}
|
||||
@ -172,7 +159,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
|
||||
if(stat(path, &buf)) {
|
||||
/* directory doesn't exist or can't be opened */
|
||||
return(-1);
|
||||
@ -180,7 +167,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
|
||||
|
||||
/* DESC */
|
||||
if(inforeq & INFRQ_DESC) {
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/desc", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
|
||||
fp = fopen(path, "r");
|
||||
if(fp == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
|
||||
@ -276,7 +263,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
|
||||
|
||||
/* FILES */
|
||||
if(inforeq & INFRQ_FILES) {
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/files", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, info->name, info->version);
|
||||
fp = fopen(path, "r");
|
||||
if(fp == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
|
||||
@ -300,7 +287,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
|
||||
|
||||
/* DEPENDS */
|
||||
if(inforeq & INFRQ_DEPENDS) {
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/depends", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
|
||||
fp = fopen(path, "r");
|
||||
if(fp == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
|
||||
@ -374,7 +361,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||
return(-1);
|
||||
}
|
||||
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version);
|
||||
oldmask = umask(0000);
|
||||
mkdir(path, 0755);
|
||||
/* make sure we have a sane umask */
|
||||
@ -386,7 +373,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||
|
||||
/* DESC */
|
||||
if(inforeq & INFRQ_DESC) {
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/desc", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
|
||||
if((fp = fopen(path, "w")) == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/desc", db->treename);
|
||||
retval = 1;
|
||||
@ -457,7 +444,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||
|
||||
/* FILES */
|
||||
if(local && (inforeq & INFRQ_FILES)) {
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/files", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, info->name, info->version);
|
||||
if((fp = fopen(path, "w")) == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/files", db->treename);
|
||||
retval = -1;
|
||||
@ -483,7 +470,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||
|
||||
/* DEPENDS */
|
||||
if(inforeq & INFRQ_DEPENDS) {
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/depends", db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
|
||||
if((fp = fopen(path, "w")) == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/depends", db->treename);
|
||||
retval = -1;
|
||||
@ -535,7 +522,9 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||
}
|
||||
|
||||
/* INSTALL */
|
||||
/* nothing needed here (script is automatically extracted) */
|
||||
if(local & (inforeq & INFRQ_SCRIPLET)) {
|
||||
/* nothing needed here (script is automatically extracted) */
|
||||
}
|
||||
|
||||
cleanup:
|
||||
umask(oldmask);
|
||||
@ -550,32 +539,34 @@ cleanup:
|
||||
int _alpm_db_remove(pmdb_t *db, pmpkg_t *info)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
int local = 0;
|
||||
|
||||
if(db == NULL || info == NULL) {
|
||||
return(-1);
|
||||
}
|
||||
|
||||
if(strcmp(db->treename, "local") == 0) {
|
||||
local = 1;
|
||||
}
|
||||
|
||||
/* DESC */
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/desc",
|
||||
db->path, db->treename, info->name, info->version);
|
||||
unlink(path);
|
||||
/* FILES */
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/files",
|
||||
db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
|
||||
unlink(path);
|
||||
/* DEPENDS */
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/depends",
|
||||
db->path, db->treename, info->name, info->version);
|
||||
unlink(path);
|
||||
/* INSTALL */
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/install",
|
||||
db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
|
||||
unlink(path);
|
||||
if(local) {
|
||||
/* FILES */
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/files", db->path, info->name, info->version);
|
||||
unlink(path);
|
||||
/* INSTALL */
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
|
||||
unlink(path);
|
||||
}
|
||||
|
||||
/* Package directory */
|
||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s",
|
||||
db->path, db->treename, info->name, info->version);
|
||||
snprintf(path, PATH_MAX, "%s/%s-%s",
|
||||
db->path, info->name, info->version);
|
||||
if(rmdir(path) == -1) {
|
||||
return(-1);
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
|
||||
RET_ERR(PM_ERR_MEMORY, NULL);
|
||||
}
|
||||
|
||||
db->path = (char *)malloc(strlen(root)+strlen(dbpath)+1);
|
||||
db->path = (char *)malloc(strlen(root)+strlen(dbpath)+strlen(treename)+2);
|
||||
if(db->path == NULL) {
|
||||
_alpm_log(PM_LOG_ERROR, "malloc failed: could not allocate %d bytes",
|
||||
strlen(root)+strlen(dbpath)+1);
|
||||
strlen(root)+strlen(dbpath)+strlen(treename)+2);
|
||||
FREE(db);
|
||||
RET_ERR(PM_ERR_MEMORY, NULL);
|
||||
}
|
||||
sprintf(db->path, "%s%s", root, dbpath);
|
||||
sprintf(db->path, "%s%s/%s", root, dbpath, treename);
|
||||
|
||||
STRNCPY(db->treename, treename, DB_TREENAME_LEN);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user