mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-11 05:48:09 -05:00
Reduce duplicate code in DB extraction
Follow-up to the previous "Only extract new DB entries" patch; move the partial extraction code inside one side of the loop so we can use the same code for actually doing file extraction. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
2f4ee4341d
commit
be2f43191d
@ -209,9 +209,9 @@ static int remove_olddir(const char *syncdbpath, alpm_list_t *dirlist)
|
|||||||
int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
||||||
{
|
{
|
||||||
char *dbfile, *dbfilepath;
|
char *dbfile, *dbfilepath;
|
||||||
const char *dbpath;
|
const char *dbpath, *syncdbpath;
|
||||||
|
alpm_list_t *filelist = NULL;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
@ -249,7 +249,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
|||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *syncdbpath = _alpm_db_path(db);
|
syncdbpath = _alpm_db_path(db);
|
||||||
|
|
||||||
/* form the path to the db location */
|
/* form the path to the db location */
|
||||||
len = strlen(dbpath) + strlen(db->treename) + strlen(DBEXT) + 1;
|
len = strlen(dbpath) + strlen(db->treename) + strlen(DBEXT) + 1;
|
||||||
@ -264,54 +264,43 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
|
|||||||
} else {
|
} else {
|
||||||
_alpm_log(PM_LOG_DEBUG, "database dir %s removed\n", _alpm_db_path(db));
|
_alpm_log(PM_LOG_DEBUG, "database dir %s removed\n", _alpm_db_path(db));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
/* Cache needs to be rebuilt */
|
|
||||||
_alpm_db_free_pkgcache(db);
|
|
||||||
|
|
||||||
checkdbdir(db);
|
|
||||||
ret = _alpm_unpack(dbfilepath, syncdbpath, NULL, 0);
|
|
||||||
|
|
||||||
free(dbfilepath);
|
|
||||||
if(ret) {
|
|
||||||
RET_ERR(PM_ERR_SYSTEM, -1);
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* if not forcing, only remove and extract what is necessary */
|
/* if not forcing, only remove and extract what is necessary */
|
||||||
alpm_list_t *onlyold = NULL;
|
|
||||||
alpm_list_t *onlynew = NULL;
|
|
||||||
alpm_list_t *olddirlist = NULL;
|
|
||||||
alpm_list_t *newdirlist = NULL;
|
alpm_list_t *newdirlist = NULL;
|
||||||
|
alpm_list_t *olddirlist = NULL;
|
||||||
|
alpm_list_t *onlyold = NULL;
|
||||||
|
|
||||||
ret = dirlist_from_tar(dbfilepath, &newdirlist);
|
ret = dirlist_from_tar(dbfilepath, &newdirlist);
|
||||||
if(ret) {
|
if(ret) {
|
||||||
|
FREELIST(newdirlist);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ret = dirlist_from_fs(syncdbpath, &olddirlist);
|
ret = dirlist_from_fs(syncdbpath, &olddirlist);
|
||||||
if(ret) {
|
if(ret) {
|
||||||
|
FREELIST(olddirlist);
|
||||||
|
FREELIST(newdirlist);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
alpm_list_diff_sorted(olddirlist, newdirlist, _alpm_str_cmp, &onlyold, &onlynew);
|
alpm_list_diff_sorted(olddirlist, newdirlist, _alpm_str_cmp, &onlyold, &filelist);
|
||||||
|
FREELIST(olddirlist);
|
||||||
|
FREELIST(newdirlist);
|
||||||
|
|
||||||
ret = remove_olddir(syncdbpath, onlyold);
|
ret = remove_olddir(syncdbpath, onlyold);
|
||||||
|
alpm_list_free(onlyold);
|
||||||
|
if(ret) {
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Cache needs to be rebuilt */
|
/* Cache needs to be rebuilt */
|
||||||
_alpm_db_free_pkgcache(db);
|
_alpm_db_free_pkgcache(db);
|
||||||
|
|
||||||
if(ret) {
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
checkdbdir(db);
|
checkdbdir(db);
|
||||||
ret = _alpm_unpack(dbfilepath, syncdbpath, onlynew, 0);
|
ret = _alpm_unpack(dbfilepath, syncdbpath, filelist, 0);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(dbfilepath);
|
free(dbfilepath);
|
||||||
alpm_list_free(onlyold);
|
|
||||||
alpm_list_free(onlynew);
|
|
||||||
FREELIST(olddirlist);
|
|
||||||
FREELIST(newdirlist);
|
|
||||||
|
|
||||||
if(ret) {
|
if(ret) {
|
||||||
RET_ERR(PM_ERR_SYSTEM, -1);
|
RET_ERR(PM_ERR_SYSTEM, -1);
|
||||||
|
Loading…
Reference in New Issue
Block a user