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;
|
struct stat buf;
|
||||||
pmdb_t *db;
|
pmdb_t *db;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
char path[PATH_MAX];
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, NULL));
|
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);
|
_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);
|
db = _alpm_db_new(handle->root, handle->dbpath, treename);
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
return(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);
|
_alpm_log(PM_LOG_DEBUG, "opening database '%s'", db->treename);
|
||||||
if(_alpm_db_open(db, DB_O_CREATE) == -1) {
|
if(_alpm_db_open(db, DB_O_CREATE) == -1) {
|
||||||
_alpm_db_free(db);
|
_alpm_db_free(db);
|
||||||
|
|
|
@ -38,27 +38,14 @@
|
||||||
|
|
||||||
int _alpm_db_open(pmdb_t *db, int mode)
|
int _alpm_db_open(pmdb_t *db, int mode)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
|
||||||
|
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(path, PATH_MAX, "%s/%s", db->path, db->treename);
|
db->handle = opendir(db->path);
|
||||||
|
|
||||||
db->handle = opendir(path);
|
|
||||||
if(db->handle == NULL) {
|
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);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +93,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, unsigned int inforeq)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* stat the entry, make sure it's a directory */
|
/* 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)) {
|
if(stat(path, &sbuf) || !S_ISDIR(sbuf.st_mode)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +126,7 @@ pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, unsigned int inforeq)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* stat the entry, make sure it's a directory */
|
/* 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)) {
|
if(!stat(path, &sbuf) && S_ISDIR(sbuf.st_mode)) {
|
||||||
isdir = 1;
|
isdir = 1;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +159,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
|
||||||
return(-1);
|
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)) {
|
if(stat(path, &buf)) {
|
||||||
/* directory doesn't exist or can't be opened */
|
/* directory doesn't exist or can't be opened */
|
||||||
return(-1);
|
return(-1);
|
||||||
|
@ -180,7 +167,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info)
|
||||||
|
|
||||||
/* DESC */
|
/* DESC */
|
||||||
if(inforeq & INFRQ_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");
|
fp = fopen(path, "r");
|
||||||
if(fp == NULL) {
|
if(fp == NULL) {
|
||||||
_alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
|
_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 */
|
/* FILES */
|
||||||
if(inforeq & INFRQ_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");
|
fp = fopen(path, "r");
|
||||||
if(fp == NULL) {
|
if(fp == NULL) {
|
||||||
_alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
|
_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 */
|
/* DEPENDS */
|
||||||
if(inforeq & INFRQ_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");
|
fp = fopen(path, "r");
|
||||||
if(fp == NULL) {
|
if(fp == NULL) {
|
||||||
_alpm_log(PM_LOG_ERROR, "%s (%s)", path, strerror(errno));
|
_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);
|
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);
|
oldmask = umask(0000);
|
||||||
mkdir(path, 0755);
|
mkdir(path, 0755);
|
||||||
/* make sure we have a sane umask */
|
/* 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 */
|
/* DESC */
|
||||||
if(inforeq & INFRQ_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) {
|
if((fp = fopen(path, "w")) == NULL) {
|
||||||
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/desc", db->treename);
|
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/desc", db->treename);
|
||||||
retval = 1;
|
retval = 1;
|
||||||
|
@ -457,7 +444,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||||
|
|
||||||
/* FILES */
|
/* FILES */
|
||||||
if(local && (inforeq & INFRQ_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) {
|
if((fp = fopen(path, "w")) == NULL) {
|
||||||
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/files", db->treename);
|
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/files", db->treename);
|
||||||
retval = -1;
|
retval = -1;
|
||||||
|
@ -483,7 +470,7 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||||
|
|
||||||
/* DEPENDS */
|
/* DEPENDS */
|
||||||
if(inforeq & INFRQ_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) {
|
if((fp = fopen(path, "w")) == NULL) {
|
||||||
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/depends", db->treename);
|
_alpm_log(PM_LOG_ERROR, "db_write: could not open file %s/depends", db->treename);
|
||||||
retval = -1;
|
retval = -1;
|
||||||
|
@ -535,7 +522,9 @@ int _alpm_db_write(pmdb_t *db, pmpkg_t *info, unsigned int inforeq)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* INSTALL */
|
/* INSTALL */
|
||||||
|
if(local & (inforeq & INFRQ_SCRIPLET)) {
|
||||||
/* nothing needed here (script is automatically extracted) */
|
/* nothing needed here (script is automatically extracted) */
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
umask(oldmask);
|
umask(oldmask);
|
||||||
|
@ -550,32 +539,34 @@ cleanup:
|
||||||
int _alpm_db_remove(pmdb_t *db, pmpkg_t *info)
|
int _alpm_db_remove(pmdb_t *db, pmpkg_t *info)
|
||||||
{
|
{
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
|
int local = 0;
|
||||||
|
|
||||||
if(db == NULL || info == NULL) {
|
if(db == NULL || info == NULL) {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(strcmp(db->treename, "local") == 0) {
|
||||||
|
local = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* DESC */
|
/* DESC */
|
||||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/desc",
|
snprintf(path, PATH_MAX, "%s/%s-%s/desc", db->path, info->name, info->version);
|
||||||
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);
|
|
||||||
unlink(path);
|
unlink(path);
|
||||||
/* DEPENDS */
|
/* DEPENDS */
|
||||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/depends",
|
snprintf(path, PATH_MAX, "%s/%s-%s/depends", db->path, info->name, info->version);
|
||||||
db->path, db->treename, 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);
|
unlink(path);
|
||||||
/* INSTALL */
|
/* INSTALL */
|
||||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s/install",
|
snprintf(path, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version);
|
||||||
db->path, db->treename, info->name, info->version);
|
|
||||||
unlink(path);
|
unlink(path);
|
||||||
|
}
|
||||||
|
|
||||||
/* Package directory */
|
/* Package directory */
|
||||||
snprintf(path, PATH_MAX, "%s/%s/%s-%s",
|
snprintf(path, PATH_MAX, "%s/%s-%s",
|
||||||
db->path, db->treename, info->name, info->version);
|
db->path, info->name, info->version);
|
||||||
if(rmdir(path) == -1) {
|
if(rmdir(path) == -1) {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,14 +48,14 @@ pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
|
||||||
RET_ERR(PM_ERR_MEMORY, NULL);
|
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) {
|
if(db->path == NULL) {
|
||||||
_alpm_log(PM_LOG_ERROR, "malloc failed: could not allocate %d bytes",
|
_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);
|
FREE(db);
|
||||||
RET_ERR(PM_ERR_MEMORY, NULL);
|
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);
|
STRNCPY(db->treename, treename, DB_TREENAME_LEN);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue