Date: Thu, 4 Aug 2005 11:47:25 GMT From: soc-andrew <soc-andrew@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 81440 for review Message-ID: <200508041147.j74BlPo4074813@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=81440 Change 81440 by soc-andrew@soc-andrew_serv on 2005/08/04 11:46:25 Install a ports tree if asked to. Improve indentation. Affected files ... .. //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.c#5 edit .. //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/extra_flow.c#6 edit .. //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/fn_install_freebsd.c#7 edit Differences ... ==== //depot/projects/soc2005/bsdinstaller/src/lib/bsdinstaller/installer/dist.c#5 (text+ko) ==== @@ -53,90 +53,89 @@ */ struct inf_file * inf_read(const char *dir, const char *dist) { - int fd, chunk, pieces; - properties dist_attr = NULL; - struct inf_file *inf; - char *tmp; - char file[PATH_MAX]; + int fd, chunk, pieces; + properties dist_attr = NULL; + 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); + /* 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) { - /* XXX */ - return NULL; - } + /* Open the file */ + fd = open(file, O_RDONLY); + if (fd == -1) { + /* XXX */ + return NULL; + } - /* Read the .inf and close */ - dist_attr = properties_read(fd); - close(fd); + /* Read the .inf and close */ + dist_attr = properties_read(fd); + close(fd); - tmp = property_find(dist_attr, "Pieces"); - if (tmp == NULL) { - /* XXX Bad file */ - properties_free(dist_attr); - return NULL; - } + tmp = property_find(dist_attr, "Pieces"); + if (tmp == NULL) { + /* XXX Bad file */ + properties_free(dist_attr); + return NULL; + } - pieces = strtol(tmp, (char **)NULL, 10); - if (pieces <= 0 || pieces == LONG_MAX) { - /* XXX Bad file */ - properties_free(dist_attr); - return NULL; - } + pieces = strtol(tmp, (char **)NULL, 10); + if (pieces <= 0 || pieces == LONG_MAX) { + /* XXX Bad file */ + 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 = 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->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; - } + 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++) { + for (chunk = 0; chunk < inf->pieces; chunk++) { - snprintf(file, PATH_MAX, "cksum.%c%c", (chunk / 26) + 'a', - (chunk % 26) + 'a'); + snprintf(file, PATH_MAX, "cksum.%c%c", (chunk / 26) + 'a', + (chunk % 26) + 'a'); - tmp = property_find(dist_attr, file); - if (tmp) { - char *len; - int length; - len = index(tmp, ' '); - length = strtol(len, (char **)NULL, 10); - if (length <= 0 || length == LONG_MAX) { - inf_free(inf); - properties_free(dist_attr); - return NULL; - } - inf->file[chunk].checksum = malloc(len-tmp+1); - strncpy(inf->file[chunk].checksum, tmp, len-tmp); - inf->file[chunk].checksum[len-tmp] = '\0'; + tmp = property_find(dist_attr, file); + if (tmp) { + char *len; + int length; + len = index(tmp, ' '); + length = strtol(len, (char **)NULL, 10); + if (length <= 0 || length == LONG_MAX) { + inf_free(inf); + properties_free(dist_attr); + return NULL; + } + inf->file[chunk].checksum = malloc(len-tmp+1); + strncpy(inf->file[chunk].checksum, tmp, len-tmp); + inf->file[chunk].checksum[len-tmp] = '\0'; + inf->file[chunk].length = length; + } else { + inf_free(inf); + properties_free(dist_attr); + return NULL; + } + } - inf->file[chunk].length = length; - } else { - inf_free(inf); - properties_free(dist_attr); - return NULL; - } - } + properties_free(dist_attr); - properties_free(dist_attr); - - return inf; + return inf; } /* @@ -144,25 +143,42 @@ */ void inf_free(struct inf_file *f) { - int chunk; + int chunk; + + if (f == NULL) + return; + + for (chunk=0; chunk < f->pieces; chunk++) + if (f->file[chunk].checksum != NULL) + free(f->file[chunk].checksum); + + if (f->file != NULL) + free(f->file); - if (f == NULL) - return; + if (f->dir != NULL) + free(f->dir); - for (chunk=0; chunk < f->pieces; chunk++) - if (f->file[chunk].checksum != NULL) - free(f->file[chunk].checksum); + if (f->dist != NULL) + free(f->dist); - if (f->file != NULL) - free(f->file); + free(f); +} - if (f->dir != NULL) - free(f->dir); +/* + * The size of the data is saved in the last 4 bytes of a gzip file. + * Extract this and return it + */ +static uint32_t +gzip_getsize(const char *name) { + uint32_t data; + FILE *fd = fopen(name, "r"); - if (f->dist != NULL) - free(f->dist); + fseek(fd, -4, SEEK_END); + fread(&data, 1, 4, fd); + fclose(fd); - free(f); + /* XXX Check in a big endian */ + return data; } /* @@ -171,91 +187,123 @@ */ static void dist_change_file_callback(int pcnt, char *name) { - /* Set the progress bar to pcnd % */ - dfui_progress_set_amount(pr, pcnt); + /* 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); + /* Set the description to the current file */ + if (name != NULL) + dfui_info_set_short_desc(dfui_progress_get_info(pr), name); - /* Update the progress bar */ - if (!dfui_be_progress_update(conn, pr, &cancelled)) - abort_backend(); + /* Update the progress bar */ + if (!dfui_be_progress_update(conn, pr, &cancelled)) + abort_backend(); } int dist_extract(struct dfui_connection *c, const char *dist) { - struct inf_file * inf; - struct archive *a; - struct archive_entry *entry; - char basename[PATH_MAX]; - char cwd[PATH_MAX]; + struct inf_file * inf; + struct archive *a; + struct archive_entry *entry; + char basename[PATH_MAX]; + char cwd[PATH_MAX]; + int is_ports = 0; + int archive_open; + uint32_t size = 0; + + getcwd(cwd, PATH_MAX); + + /* Read the inf file and get the basename of the files to extract */ + if (dist[0] == 's') { + /* This is a source dist */ + inf = inf_read("src", dist); + snprintf(basename, PATH_MAX, "%s/src/%s.", base, dist); + } else if (strncmp("ports", dist, 6) == 0) { + inf = inf_read(dist, dist); + snprintf(basename, PATH_MAX, "%s/%s/%s.tgz", base, dist, dist); + is_ports = 1; + size = gzip_getsize(basename); + } else { + inf = inf_read(dist, dist); + snprintf(basename, PATH_MAX, "%s/%s/%s.", base, dist, dist); + } + if (is_ports == 0 && inf == NULL) { + /* XXX Problem with inf file */ + printf("ERROR: No inf file\n"); + return 1; + } - getcwd(cwd, PATH_MAX); + /* Create the progress bar */ + pr = dfui_progress_new(dfui_info_new( + "Extracting", + /* + * Just call it the ports tree as it will be changed + * in the non ports tree case + */ + "Ports Tree", + ""), + 0); - if (dist[0] == 's') { - /* This is a source dist */ - inf = inf_read("src", dist); - snprintf(basename, PATH_MAX, "%s/src/%s.", base, dist); - } else { - inf = inf_read(dist, dist); - snprintf(basename, PATH_MAX, "%s/%s/%s.", base, dist, dist); - } - if (inf == NULL) { - /* XXX Problem with inf file */ - return 1; - } + if (!dfui_be_progress_begin(c, pr)) + abort_backend(); + conn = c; - pr = dfui_progress_new(dfui_info_new( - "Extracting", - "No file", - ""), - 0); + a = archive_read_new(); + archive_read_support_compression_all(a); + archive_read_support_format_all(a); - if (!dfui_be_progress_begin(c, pr)) - abort_backend(); - conn = c; + if (is_ports == 0) { + archive_open = read_open_split(a, basename, (inf->pieces / 26) + 'a', + (inf->pieces % 26) + 'a', dist_change_file_callback); + } else { + archive_open = archive_read_open_file(a, basename, 10240); + } - a = archive_read_new(); - archive_read_support_compression_all(a); - archive_read_support_format_all(a); - if(read_open_split(a, basename, (inf->pieces / 26) + 'a', - (inf->pieces % 26) + 'a', dist_change_file_callback) != ARCHIVE_OK) { - printf("ERROR: %s\n", archive_error_string(a)); - archive_read_finish(a); - inf_free(inf); - dfui_progress_free(pr); - return 1; - } + if(archive_open != ARCHIVE_OK) { + /* XXX change to i_log */ + printf("ERROR: %s\n", archive_error_string(a)); + archive_read_finish(a); + inf_free(inf); + dfui_progress_free(pr); + return 1; + } - chdir(location); - while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { - archive_read_extract(a, entry, 0); - archive_read_data_skip(a); - } + chdir(location); + while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { + archive_read_extract(a, entry, 0); + archive_read_data_skip(a); + if (is_ports == 1) { + /* If this is ports display a bar dependent on the + * percent decompressed + */ + uint64_t pos = archive_read_header_position(a); + uint32_t pcnt = (uint32_t)(((double)pos/size)*100); + dfui_progress_set_amount(pr, pcnt); + if (!dfui_be_progress_update(conn, pr, &cancelled)) + abort_backend(); + } + } - archive_read_finish(a); + archive_read_finish(a); - chdir(cwd); - inf_free(inf); - dfui_progress_free(pr); + chdir(cwd); + inf_free(inf); + dfui_progress_free(pr); - return 0; + return 0; } void dist_set_location(const char *loc) { - strlcpy(location, loc, PATH_MAX); + strlcpy(location, loc, PATH_MAX); } void dist_set_base(const char *path) { - - if (path[0] =='/') { - strlcpy(base, path, PATH_MAX); - } else { - char cwd[PATH_MAX]; - getcwd(cwd, PATH_MAX); - snprintf(base, PATH_MAX, "%s/%s", cwd, path); - } + if (path[0] =='/') { + strlcpy(base, path, PATH_MAX); + } else { + char cwd[PATH_MAX]; + getcwd(cwd, PATH_MAX); + snprintf(base, PATH_MAX, "%s/%s", cwd, path); + } } ==== //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/extra_flow.c#6 (text+ko) ==== @@ -65,6 +65,7 @@ #ifdef __amd64__ { "lib32", "32bit Libraries" }, #endif + { "ports", "Ports tree" }, { "src", "Source" }, { NULL, NULL } }; ==== //depot/projects/soc2005/bsdinstaller/src/usr.sbin/bsdinstaller/backend/fn_install_freebsd.c#7 (text+ko) ==== @@ -184,6 +184,9 @@ return a->result; } +/* + * Do the actual install + */ int do_install(struct i_fn_args *a) { @@ -196,33 +199,43 @@ struct commands *cmds; struct utsname name; int install_src = 0; + int install_ports = 0; uname(&name); + /* Set base to the location of the dists */ snprintf(base, PATH_MAX, "/usr/%s", name.release); i_log(a, "<<< Extracting distrubutions from %s", base); dist_set_base(base); dist_set_location("/mnt"); - aura_dict_rewind(a->dists); /* * Install the selected dists */ + aura_dict_rewind(a->dists); while (!aura_dict_eof(a->dists)) { + /* Set dist_name */ aura_dict_get_current_key(a->dists, &rk, &rk_len); strlcpy(dist_name, rk, 32); if (rk_len < 32) dist_name[rk_len] = '\0'; - + + /* If this dist is special set the correct flag */ if (strncmp("src", dist_name, 4) == 0) { install_src = 1; + } else if (strncmp("ports", dist_name, 6) == 0) { + install_ports = 1; + + /* Otherwise install the dist */ } else if( dist_extract(a->c, dist_name) != 0) { inform(a->c, _("Distribution %s was not installed."), dist_name); return 0; } aura_dict_next(a->dists); } + + /* The src and ports dists are special and installed last */ if (install_src == 1) { int src_dist = 0; dist_set_location("/mnt/usr/src"); @@ -230,6 +243,10 @@ dist_extract(a->c, SrcDistTable[src_dist]); } } + if (install_ports == 1) { + dist_set_location("/mnt/usr"); + printf("%d\n", dist_extract(a->c, "ports")); + } i_log(a, ">>> Done"); i_log(a, "");
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200508041147.j74BlPo4074813>
