This commit is contained in:
guinux 2017-06-03 14:46:08 +02:00
parent 57acdc25f3
commit bd81be2659
2 changed files with 46 additions and 50 deletions

View File

@ -134,7 +134,7 @@ class AlpmConfig {
}
}
public Alpm.Handle? get_handle () {
public Alpm.Handle? get_handle (bool files_db = false) {
Alpm.Errno error;
Alpm.Handle? handle = new Alpm.Handle (rootdir, dbpath, out error);
if (error == Alpm.Errno.DB_VERSION) {
@ -150,6 +150,9 @@ class AlpmConfig {
return null;
}
// define options
if (files_db) {
handle.dbext = ".files";
}
handle.logfile = logfile;
handle.gpgdir = gpgdir;
handle.arch = arch;
@ -195,20 +198,6 @@ class AlpmConfig {
return handle;
}
public Alpm.Handle? get_files_handle () {
Alpm.Handle? handle = new Alpm.Handle (rootdir, dbpath, null);
if (handle == null) {
return null;
}
// define options
handle.dbext = ".files";
// register dbs
foreach (unowned AlpmRepo repo in repo_order) {
handle.register_syncdb (repo.name, 0);
}
return handle;
}
void parse_file (string path, string? section = null) {
string? current_section = section;
var file = GLib.File.new_for_path (path);

View File

@ -223,7 +223,7 @@ namespace Pamac {
alpm_handle.logcb = (Alpm.LogCallBack) cb_log;
lockfile = GLib.File.new_for_path (alpm_handle.lockfile);
}
files_handle = alpm_config.get_files_handle ();
files_handle = alpm_config.get_handle (true);
}
private bool check_extern_lock () {
@ -452,6 +452,31 @@ namespace Pamac {
});
}
private bool update_dbs (Alpm.Handle handle, int force) {
bool success = false;
unowned Alpm.List<unowned Alpm.DB> syncdbs = handle.syncdbs;
while (syncdbs != null) {
if (cancellable.is_cancelled ()) {
break;
}
unowned Alpm.DB db = syncdbs.data;
if (db.update (force) >= 0) {
success = true;
} else {
Alpm.Errno errno = handle.errno ();
current_error.errno = (uint) errno;
if (errno != 0) {
// download error details are set in cb_fetch
if (errno != Alpm.Errno.EXTERNAL_DOWNLOAD) {
current_error.details = { Alpm.strerror (errno) };
}
}
}
syncdbs.next ();
}
return success;
}
private void refresh () {
current_error = ErrorInfos ();
if (!databases_lock_mutex.trylock ()) {
@ -466,44 +491,26 @@ namespace Pamac {
return;
}
write_log_file ("synchronizing package lists");
int force = (force_refresh) ? 1 : 0;
uint success = 0;
cancellable.reset ();
string[] dbexts = {".db", ".files"};
unowned Alpm.List<unowned Alpm.DB> syncdbs = alpm_handle.syncdbs;
while (syncdbs != null) {
unowned Alpm.DB db = syncdbs.data;
if (cancellable.is_cancelled ()) {
alpm_handle.dbext = ".db";
refresh_finished (false);
databases_lock_mutex.unlock ();
return;
}
foreach (unowned string dbext in dbexts) {
alpm_handle.dbext = dbext;
if (db.update (force) >= 0) {
success++;
} else {
Alpm.Errno errno = alpm_handle.errno ();
current_error.errno = (uint) errno;
if (errno != 0) {
// download error details are set in cb_fetch
if (errno != Alpm.Errno.EXTERNAL_DOWNLOAD) {
current_error.details = { Alpm.strerror (errno) };
}
}
}
}
syncdbs.next ();
int force = (force_refresh) ? 1 : 0;
// update ".db"
bool success = update_dbs (alpm_handle, force);
if (cancellable.is_cancelled ()) {
refresh_finished (false);
databases_lock_mutex.unlock ();
return;
}
alpm_handle.dbext = ".db";
// We should always succeed if at least one DB was upgraded - we may possibly
// fail later with unresolved deps, but that should be rare, and would be expected
if (success == 0) {
// update ".files", do not need to know if we succeeded
update_dbs (files_handle, force);
if (cancellable.is_cancelled ()) {
refresh_finished (false);
} else if (success) {
// We should always succeed if at least one DB was upgraded - we may possibly
// fail later with unresolved deps, but that should be rare, and would be expected
refresh_finished (true);
} else {
current_error.message = _("Failed to synchronize any databases");
refresh_finished (false);
} else {
refresh_finished (true);
}
databases_lock_mutex.unlock ();
}