Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Jul 2005 14:40:16 GMT
From:      soc-andrew <soc-andrew@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 80041 for review
Message-ID:  <200507121440.j6CEeGLb065348@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=80041

Change 80041 by soc-andrew@soc-andrew_serv on 2005/07/12 14:40:16

	Display a progress bar during the installation of each distribution.
	Add more comments to the code I've added to aid maintenance.

Affected files ...

.. //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.c#4 edit
.. //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.h#3 edit
.. //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/fn_install_freebsd.c#3 edit

Differences ...

==== //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.c#4 (text+ko) ====

@@ -40,6 +40,9 @@
 
 static char base[PATH_MAX];
 static char location[PATH_MAX];
+struct dfui_progress *pr = NULL;
+struct dfui_connection *conn = NULL;
+int cancelled = 0;
 
 static void dist_change_file_callback(int, char *);
 
@@ -50,40 +53,58 @@
  */
 struct inf_file *
 inf_read(const char *dir, const char *dist) {
-  int fd, chunk;
+  int fd, chunk, pieces;
   properties dist_attr = NULL;
-  struct inf_file *inf = malloc(sizeof(struct inf_file));
+  struct inf_file *inf;
   char *tmp;
   char file[PATH_MAX];
 
+  /* Set file to the location of the .inf file */
   snprintf(file, PATH_MAX, "%s/%s/%s.inf", base, dir, dist);
 
+  /* Open the file */
   fd = open(file, O_RDONLY);
-  if (fd == -1)
+  if (fd == -1) {
+    /* XXX */
     return NULL;
+  }
 
+  /* Read the .inf and close */
   dist_attr = properties_read(fd);
   close(fd);
 
   tmp = property_find(dist_attr, "Pieces");
   if (tmp == NULL) {
     /* XXX Bad file */
-    free(inf);
     properties_free(dist_attr);
     return NULL;
   }
-  inf->pieces = strtol(tmp, (char **)NULL, 10);
-  if (inf->pieces <= 0 || inf->pieces == LONG_MAX) {
+
+  pieces = strtol(tmp, (char **)NULL, 10);
+  if (pieces <= 0 || pieces == LONG_MAX) {
     /* XXX Bad file */
-    free(inf);
+    properties_free(dist_attr);
+    return NULL;
+  }
+
+  inf = malloc(sizeof(struct inf_file));
+  if (inf == NULL) {
+    /* XXX Out of memory */
     properties_free(dist_attr);
     return NULL;
   }
 
+  inf->pieces = pieces;
   inf->dir = strdup(dir);
   inf->dist = strdup(dist);
 
   inf->file = malloc(sizeof(struct file) * inf->pieces);
+  if (inf->file == NULL) {
+    /* XXX Out of memory */
+    inf_free(inf);
+    properties_free(dist_attr);
+    return NULL;
+  }
 
   for (chunk = 0; chunk < inf->pieces; chunk++) {
 
@@ -118,6 +139,9 @@
   return inf;
 }
 
+/*
+ * Free the struct inf_file
+ */
 void
 inf_free(struct inf_file *f) {
   int chunk;
@@ -141,17 +165,26 @@
   free(f);
 }
 
+/*
+ * Update the progress bar for the current
+ * when the current file changes.
+ */
 static void
 dist_change_file_callback(int pcnt, char *name) {
-  printf("%d%%", pcnt);
-  if (name)
-    printf(" %s", name);
+  /* Set the progress bar to pcnd % */
+  dfui_progress_set_amount(pr, pcnt);
+
+  /* Set the description to the current file */
+  if (name != NULL)
+    dfui_info_set_short_desc(dfui_progress_get_info(pr), name);
 
-  putchar('\n');
+  /* Update the progress bar */
+  if (!dfui_be_progress_update(conn, pr, &cancelled)) 
+    abort_backend();
 }
 
-void
-dist_extract(const char *dist) {
+int
+dist_extract(struct dfui_connection *c, const char *dist) {
   struct inf_file * inf;
   struct archive *a;
   struct archive_entry *entry;
@@ -170,9 +203,19 @@
   }
   if (inf == NULL) {
     /* XXX Problem with inf file */
-    return;
+    return 1;
   }
 
+  pr = dfui_progress_new(dfui_info_new(
+           "Extracting",
+           "No file",
+           ""),
+         0);
+
+  if (!dfui_be_progress_begin(c, pr))
+    abort_backend();
+  conn = c;
+
   a = archive_read_new();
   archive_read_support_compression_all(a);
   archive_read_support_format_all(a);
@@ -181,7 +224,8 @@
     printf("ERROR: %s\n", archive_error_string(a));
     archive_read_finish(a);
     inf_free(inf);
-    return;
+    dfui_progress_free(pr);
+    return 1;
   }
 
   chdir(location);
@@ -190,11 +234,13 @@
     archive_read_data_skip(a);
   }
 
-  chdir(cwd);
-
   archive_read_finish(a);
 
+  chdir(cwd);
   inf_free(inf);
+  dfui_progress_free(pr);
+
+  return 0;
 }
 
 void

==== //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.h#3 (text+ko) ====

@@ -28,6 +28,8 @@
 #ifndef _INSTALLER_DIST_H_
 #define _INSTALLER_DIST_H_
 
+#include <dfui/dfui.h>
+
 struct file {
 	char *checksum;
 	int length;
@@ -42,7 +44,7 @@
 
 struct inf_file *inf_read(const char *, const char *);
 void inf_free(struct inf_file *);
-void dist_extract(const char *);
+int dist_extract(struct dfui_connection *, const char *);
 void dist_set_base(const char *);
 void dist_set_location(const char *);
 

==== //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/fn_install_freebsd.c#3 (text+ko) ====

@@ -169,7 +169,7 @@
 	i_log(a, "<<< Extracting distrubutions from %s", base);
 	dist_set_base(base);
 	dist_set_location("/mnt");
-	dist_extract("base");
+	dist_extract(a->c, "base");
 	i_log(a, ">>> Done");
 	return 1;
 }
@@ -352,10 +352,12 @@
 void
 fn_install_os(struct i_fn_args *a)
 {
+	i_log(a, "1111");
 	pre_install(a);
-
+	i_log(a, "2222");
 	do_install(a);
-
+	i_log(a, "3333");
 	post_install(a);
+	i_log(a, "4444");
 }
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200507121440.j6CEeGLb065348>