Bug 1830 - Progress bars not updating correctly with scripts....
Status: RESOLVED FIXED
Alias: None
Product: Loki Setup
Classification: Unclassified
Component: General
Version: unspecified
Hardware: PC Linux
: P2 normal
Assignee: St
QA Contact:
URL:
Depends on:
Blocks:
 
Reported: 2004-06-29 10:55 EDT by Derek Gaston
Modified: 2004-06-29 23:21:46 EDT
0 users

See Also:


Attachments
Fixes copy.c (823 bytes, patch)
2004-06-29 10:58 EDT, Derek Gaston
Fixes gtk_ui.c (63.17 KB, patch)
2004-06-29 10:59 EDT, Derek Gaston

Description Derek Gaston 2004-06-29 10:55:12 EDT
Progress bars were not being updated correctly with script sizes.  Here are a
couple of patches that resolve this issue.

The one issue that still remains is that rc is still returning _1_ from
run_script even if the script explicitly exits with 0.  To get around this I
just stopped testing for it - I don't think it will be a problem to increment
the progress bar even if the script failed.

This first patch fixes copy.c.  First of all it passes in the correct size and
progress (I made the progress be size/2 just so that it looks like it is working
on something) into the update function.

The next fix is to first allow it to add bytes to installed_bytes (by removing
the test on rc) and next to actually add the right number of bytes (before it
was using sz which for me = "10M" and NOT the number of bytes).

Here is the first diff:

--- copy.c.old        2004-04-30 21:53:10.000000000 -0600
+++ copy.c      2004-06-29 08:41:37.000000000 -0600
@@ -753,7 +753,7 @@
        }
        if ( update ) {
                if (msg != NULL)
-                       rc = update(info, msg, 0, 0, current_option_txt);
+                       rc = update(info, msg, size_node(info, node)/2,
size_node(info, node), current_option_txt);
                else
                        rc = update(info, _("Running script"), 0, 0,
current_option_txt);
                if ( !rc )
@@ -862,9 +862,9 @@
                                rc = copy_script(info, node,
                                            xmlNodeListGetString(info->config,
node->childs, 1),
                                            path, update, from_cdrom, msg);
-                               if (rc == 0 && sz) {
-                                       info->installed_bytes += atoi(sz);
-                                       size += atoi(sz);
+                               if (size_node(info, node)) {
+                                       info->installed_bytes += size_node(info,
node);
+                                       size += size_node(info, node);
                                }
                                xmlFree(sz); xmlFree(msg);





#####################

Next up is a patch to gtk_ui.c

First of all I create a new static variable: last_installed_bytes.  This
variable holds the amount of bytes that were installed on the last pass through
(much like last_update).  This variable is necessary because there is actually a
bug in this function that if two different installed files report the same
progress one right after another - the GUI won't be updated.  I ran into this
because I had 2 scripts of the same size right after eachother - and it wasn't
updating the GUI.

The rest of the new pieces should be self explanatory - and all deal with this
new variable.



--- gtk_ui.c.old      2004-05-11 19:45:22.000000000 -0600
+++ gtk_ui.c    2004-06-29 07:57:27.000000000 -0600
@@ -1747,6 +1747,7 @@
 static int gtkui_update(install_info *info, const char *path, size_t progress,
size_t size, const char *current)
 {
     static gfloat last_update = -1;
+    static gdouble last_installed_bytes = -1;
     GtkWidget *widget;
     int textlen;
     const char *text;
@@ -1762,7 +1763,7 @@
     } else { /* "Running script" */
         new_update = 1.0;
     }
-    if ( (int)(new_update*100) != (int)(last_update*100) ) {
+    if ( ( (int)(new_update*100) != (int)(last_update*100) ) || (
last_installed_bytes !=  (gdouble)info->installed_bytes ) ) {
         if ( new_update == 1.0 ) {
             last_update = 0.0;
         } else {
@@ -1789,6 +1790,7 @@
         widget = glade_xml_get_widget(setup_glade, "current_file_progress");
         gtk_progress_bar_update(GTK_PROGRESS_BAR(widget), new_update);
         new_update = (gdouble)info->installed_bytes / (gdouble)info->install_size;
+       last_installed_bytes=(gdouble)info->installed_bytes;
        if (new_update > 1.0) {
            new_update = 1.0;
        }




Let me know if you have any problems with these.

Derek
Comment 1 Derek Gaston 2004-06-29 10:58:08 EDT
Created attachment 421 [details]
Fixes copy.c

Patch for copy.c - incase it got garbled in my bug report
Comment 2 Derek Gaston 2004-06-29 10:59:42 EDT
Created attachment 422 [details]
Fixes gtk_ui.c

Just in case the gtk_ui.c patch got garbled.
Comment 3 Derek Gaston 2004-06-29 15:05:58 EDT
One more thing.... Because of this change - the status of the commandline
installation isn't updated properly.. Here is my dialog_update from dialog_ui.c
that fixes this problem (sorry for no diff - my dialog_ui.c is so hacked up
right now that I couldn't get a good diff out of it - but the function is small
enough it shouldn't be a problem)....



static
int dialog_update(install_info *info, const char *path, size_t progress, 
				  size_t size, const char *current)
{
	char buf[PATH_MAX];
    static char previous[200] = "";
    int percent=-1;

    if(strcmp(previous, current)){
        strncpy(previous,current, sizeof(previous));
		/* FIXME: Anything useful to be done here? */
	}

	if(size) {
	        percent = (int) (((float)progress/(float)size)*100.0);
	} else {
		percent=100;
	}
	
	if ( progress && size && !path ) {
		snprintf(buf, sizeof(buf), _("Installing %s ..."), current);
		dialog_gauge_update(_("Installing..."), buf, percent);
	} else { /* Script */
		dialog_gauge_update(_("Installing..."), path, percent);
	}
	return 1;
}
Comment 4 St 2004-06-29 15:15:06 EDT
OK, I'll take a look at all of this...
Comment 5 Derek Gaston 2004-06-29 16:53:50 EDT
And personally I think that the progress bar should be updated with something
closer to (in dialog_ui.c):

percent = (int) (((float)(info->installed_bytes) /
(float)(info->install_size))*100);

I would just rather see total install progress instead of single file - but
maybe that's just me.

Derek
Comment 6 St 2004-06-29 23:05:35 EDT
Only problem with your patches is the abuse of size_node() which can be a very costly operation if the 
size tag is not present. I'll fix this as I merge them though.

Also I agree we should show the global progress bar in the dialog UI, so I'll do that too. ;-)
Comment 7 St 2004-06-29 23:21:46 EDT
OK, it's all in CVS now.