diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 27218d6..d4c7444 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -159,19 +159,41 @@ static int sync_cleancache(int level) if(alpm_pkg_load(path, 0, &localpkg) != 0 || localpkg == NULL) { continue; } - /* check if this package is in the local DB */ - dbpkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(localpkg)); - if(dbpkg == NULL) { - /* delete package, not present in local DB */ - unlink(path); - } else if(alpm_pkg_vercmp(alpm_pkg_get_version(localpkg), + int delete = 0; + int local = 0; + if(local) { + /* check if this package is in the local DB */ + dbpkg = alpm_db_get_pkg(db_local, alpm_pkg_get_name(localpkg)); + if(dbpkg == NULL) { + /* delete package, not present in local DB */ + delete = 1; + } else if(alpm_pkg_vercmp(alpm_pkg_get_version(localpkg), alpm_pkg_get_version(dbpkg)) != 0) { - /* delete package, it was found but version differs */ - unlink(path); + /* delete package, it was found but version differs */ + delete = 1; + } + /* else version was the same, so keep the package */ + /* free the local file package */ + alpm_pkg_free(localpkg); + } else { + alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); + alpm_list_t *j; + + delete = 1; + for(j = sync_dbs; j; j = alpm_list_next(j)) { + pmdb_t *db = alpm_list_getdata(j); + pmpkg_t *findpkg = alpm_db_get_pkg(db, alpm_pkg_get_name(localpkg)); + if(findpkg && alpm_pkg_vercmp(alpm_pkg_get_version(localpkg), + alpm_pkg_get_version(findpkg)) == 0) { + delete = 0; + break; + } + } + } + + if(delete) { + printf("unlink %s\n", path); } - /* else version was the same, so keep the package */ - /* free the local file package */ - alpm_pkg_free(localpkg); } printf(_("done.\n")); } else {