Commit 6e91ad25 authored by guinux's avatar guinux

fix #570

parent 5e57ce8a
......@@ -19,6 +19,7 @@
Pamac.AlpmUtils alpm_utils;
string current_filename;
uint64 prevprogress;
uint64 total_download;
HashTable<string, uint64?> multi_progress;
......@@ -65,7 +66,8 @@ class DownloadServer: Object {
string? filename = dload_queue.try_pop_unlocked ();
dload_queue.unlock ();
if (filename != null) {
alpm_utils.emit_event (Alpm.Event.Type.PKGDOWNLOAD_START, 0, {filename});
current_filename = filename;
alpm_utils.compute_multi_download_progress ();
int ret = curl_dload (curl, "%s/%s/%s/%s".printf (server_url, repo, alpm_utils.alpm_handle.arch, filename), cachedir, 0);
if (ret == -1) {
// error
......@@ -116,7 +118,6 @@ namespace Pamac {
public signal void emit_unresolvables (string[] unresolvables);
public signal void emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target);
public signal void emit_download (string filename, uint64 xfered, uint64 total);
public signal void emit_multi_download (uint64 xfered, uint64 total);
public signal void emit_totaldownload (uint64 total);
public signal void emit_log (uint level, string msg);
public signal void refresh_finished (bool success);
......@@ -965,18 +966,16 @@ namespace Pamac {
return summary;
}
bool compute_multi_download_progress () {
public bool compute_multi_download_progress () {
uint64 total_progress = 0;
multi_progress.foreach ((filename, progress) => {
total_progress += progress;
});
emit_multi_download (total_progress, total_download);
emit_download (current_filename, total_progress, total_download);
return true;
}
void download_files (uint64 max_parallel_downloads) {
// use to track downloads progress
uint timeout_id = Timeout.add (500, compute_multi_download_progress);
multi_progress = new HashTable<string, uint64?> (str_hash, str_equal);
// create the table of async queues
// one queue per repo
......@@ -1023,8 +1022,12 @@ namespace Pamac {
}
syncdbs.next ();
}
emit_totaldownload (total_download);
emit_event (Alpm.Event.Type.RETRIEVE_START, 0, {});
emit_multi_download (0, total_download);
current_filename = "";
emit_download ("", 0, total_download);
// use to track downloads progress
uint timeout_id = Timeout.add (500, compute_multi_download_progress);
// create a thread pool which will download files
// there will be two threads per mirror
try {
......@@ -1055,8 +1058,9 @@ namespace Pamac {
}
// stop compute_multi_download_progress
Source.remove (timeout_id);
emit_multi_download (total_download, total_download);
alpm_utils.emit_event (Alpm.Event.Type.RETRIEVE_DONE, 0, {});
emit_download ("", total_download, total_download);
emit_event (Alpm.Event.Type.RETRIEVE_DONE, 0, {});
emit_totaldownload (0);
}
internal void trans_commit () {
......@@ -1439,21 +1443,19 @@ int cb_download (void* data, uint64 dltotal, uint64 dlnow, uint64 ultotal, uint6
return 1;
}
string filename = (string) data;
if (unlikely (dlnow == 0 || dltotal == 0 || prevprogress == dltotal)) {
return 0;
} else if (unlikely (prevprogress == 0)) {
alpm_utils.emit_download (filename, 0, dltotal);
alpm_utils.emit_download (filename, dlnow, dltotal);
alpm_utils.emit_download ((string) data, 0, dltotal);
alpm_utils.emit_download ((string) data, dlnow, dltotal);
alpm_utils.timer.start ();
} else if (unlikely (dlnow == dltotal)) {
alpm_utils.emit_download (filename, dlnow, dltotal);
alpm_utils.emit_download ((string) data, dlnow, dltotal);
alpm_utils.timer.stop ();
} else if (likely (alpm_utils.timer.elapsed () < 0.5)) {
return 0;
} else {
alpm_utils.emit_download (filename, dlnow, dltotal);
alpm_utils.emit_download ((string) data, dlnow, dltotal);
alpm_utils.timer.start ();
}
......
......@@ -53,7 +53,6 @@ namespace Pamac {
public signal void emit_unresolvables (string[] unresolvables);
public signal void emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target);
public signal void emit_download (string filename, uint64 xfered, uint64 total);
public signal void emit_multi_download (uint64 xfered, uint64 total);
public signal void emit_totaldownload (uint64 total);
public signal void emit_log (uint level, string msg);
public signal void set_pkgreason_finished ();
......@@ -97,9 +96,6 @@ namespace Pamac {
alpm_utils.emit_download.connect ((filename, xfered, total) => {
emit_download (filename, xfered, total);
});
alpm_utils.emit_multi_download.connect ((xfered, total) => {
emit_multi_download (xfered, total);
});
alpm_utils.emit_totaldownload.connect ((total) => {
emit_totaldownload (total);
});
......
......@@ -950,14 +950,6 @@ namespace Pamac {
case 27: //Alpm.Event.Type.RETRIEVE_FAILED
stop_downloading ();
break;
case 28: //Alpm.Event.Type.PKGDOWNLOAD_START
// special case handle differently
string name_version_release = details[0].slice (0, details[0].last_index_of_char ('-'));
string name_version = name_version_release.slice (0, name_version_release.last_index_of_char ('-'));
string name = name_version.slice (0, name_version.last_index_of_char ('-'));
string version_release = details[0].replace (name + "-", "").replace (".pkg.tar.xz", "");
current_action = dgettext (null, "Downloading %s").printf ("%s (%s)".printf (name, version_release)) + "...";
break;
case 31: //Alpm.Event.Type.DISKSPACE_START
current_action = dgettext (null, "Checking available disk space") + "...";
break;
......@@ -1068,8 +1060,15 @@ namespace Pamac {
var text = new StringBuilder ();
double fraction;
if (total_download > 0) {
if (filename != "" && filename != current_filename) {
current_filename = filename;
string name_version_release = filename.slice (0, filename.last_index_of_char ('-'));
string name_version = name_version_release.slice (0, name_version_release.last_index_of_char ('-'));
string name = name_version.slice (0, name_version.last_index_of_char ('-'));
string version_release = filename.replace (name + "-", "").replace (".pkg.tar.xz", "");
current_action = dgettext (null, "Downloading %s").printf ("%s (%s)".printf (name, version_release)) + "...";
}
if (xfered == 0) {
// start download pkg is handled by Alpm.Event.Type.PKGDOWNLOAD_START
previous_xfered = 0;
fraction = current_progress;
text.append (current_status);
......@@ -1161,58 +1160,6 @@ namespace Pamac {
emit_download_progress (current_action, current_status, current_progress);
}
void on_emit_multi_download (uint64 xfered, uint64 total) {
var text = new StringBuilder ();
double fraction;
if (xfered == 0) {
// start download pkg is handled by Alpm.Event.Type.PKGDOWNLOAD_START
previous_xfered = 0;
fraction = current_progress;
text.append (current_status);
timer.start ();
} else {
if (timer.elapsed () > 0.1) {
download_rate = ((download_rate * rates_nb) + (uint64) ((xfered - previous_xfered) / timer.elapsed ())) / (rates_nb + 1);
rates_nb++;
}
already_downloaded += xfered - previous_xfered;
previous_xfered = xfered;
fraction = (double) already_downloaded / total;
if (fraction <= 1) {
text.append ("%s/%s".printf (format_size (already_downloaded), format_size (total)));
uint64 remaining_seconds = 0;
if (download_rate > 0) {
remaining_seconds = (total - already_downloaded) / download_rate;
}
// display remaining time after 5s and only if more than 10s are remaining
if (remaining_seconds > 9 && rates_nb > 9) {
text.append (" ");
if (remaining_seconds <= 50) {
text.append (dgettext (null, "About %u seconds remaining").printf ((uint) Math.ceilf ((float) remaining_seconds / 10) * 10));
} else {
uint remaining_minutes = (uint) Math.ceilf ((float) remaining_seconds / 60);
text.append (dngettext (null, "About %lu minute remaining",
"About %lu minutes remaining", remaining_minutes).printf (remaining_minutes));
}
}
} else {
text.append ("%s".printf (format_size (already_downloaded)));
}
if (xfered == total) {
current_filename = "";
} else {
timer.start ();
}
}
if (fraction != current_progress) {
current_progress = fraction;
}
if (text.str != current_status) {
current_status = text.str;
}
emit_download_progress (current_action, current_status, current_progress);
}
void on_emit_totaldownload (uint64 total) {
download_rate = 0;
rates_nb = 0;
......@@ -1465,7 +1412,6 @@ namespace Pamac {
transaction_interface.emit_unresolvables.connect (on_emit_unresolvables);
transaction_interface.emit_progress.connect (on_emit_progress);
transaction_interface.emit_download.connect (on_emit_download);
transaction_interface.emit_multi_download.connect (on_emit_multi_download);
transaction_interface.emit_totaldownload.connect (on_emit_totaldownload);
transaction_interface.emit_log.connect (on_emit_log);
transaction_interface.trans_prepare_finished.connect (on_trans_prepare_finished);
......@@ -1477,7 +1423,6 @@ namespace Pamac {
transaction_interface.emit_providers.disconnect (on_emit_providers);
transaction_interface.emit_progress.disconnect (on_emit_progress);
transaction_interface.emit_download.disconnect (on_emit_download);
transaction_interface.emit_multi_download.disconnect (on_emit_multi_download);
transaction_interface.emit_totaldownload.disconnect (on_emit_totaldownload);
transaction_interface.emit_log.disconnect (on_emit_log);
transaction_interface.trans_prepare_finished.disconnect (on_trans_prepare_finished);
......
......@@ -43,7 +43,6 @@ namespace Pamac {
public signal void emit_unresolvables (string[] unresolvables);
public signal void emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target);
public signal void emit_download (string filename, uint64 xfered, uint64 total);
public signal void emit_multi_download (uint64 xfered, uint64 total);
public signal void emit_totaldownload (uint64 total);
public signal void emit_log (uint level, string msg);
public signal void set_pkgreason_finished ();
......
......@@ -46,7 +46,6 @@ namespace Pamac {
public signal void emit_unresolvables (string[] unresolvables);
public signal void emit_progress (uint progress, string pkgname, uint percent, uint n_targets, uint current_target);
public signal void emit_download (string filename, uint64 xfered, uint64 total);
public signal void emit_multi_download (uint64 xfered, uint64 total);
public signal void emit_totaldownload (uint64 total);
public signal void emit_log (uint level, string msg);
public signal void set_pkgreason_finished ();
......@@ -312,10 +311,6 @@ namespace Pamac {
emit_download (filename, xfered, total);
}
void on_emit_multi_download (uint64 xfered, uint64 total) {
emit_multi_download (xfered, total);
}
void on_emit_totaldownload (uint64 total) {
emit_totaldownload (total);
}
......@@ -356,7 +351,6 @@ namespace Pamac {
system_daemon.emit_unresolvables.connect (on_emit_unresolvables);
system_daemon.emit_progress.connect (on_emit_progress);
system_daemon.emit_download.connect (on_emit_download);
system_daemon.emit_multi_download.connect (on_emit_multi_download);
system_daemon.emit_totaldownload.connect (on_emit_totaldownload);
system_daemon.emit_log.connect (on_emit_log);
system_daemon.database_modified.connect (on_database_modified);
......
......@@ -38,9 +38,6 @@ namespace Pamac {
alpm_utils.emit_download.connect ((filename, xfered, total) => {
emit_download (filename, xfered, total);
});
alpm_utils.emit_multi_download.connect ((xfered, total) => {
emit_multi_download (xfered, total);
});
alpm_utils.emit_totaldownload.connect ((total) => {
emit_totaldownload (total);
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment