From 7df683409a22ecfdf576fb307ce9f015a4ac53d9 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Fri, 5 Nov 2004 13:47:20 +0000 Subject: create choose_iso_in_directory() out of try_with_directory() --- mdk-stage1/directory.c | 131 ++++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 62 deletions(-) (limited to 'mdk-stage1/directory.c') diff --git a/mdk-stage1/directory.c b/mdk-stage1/directory.c index fdefac5f1..e1535c6e3 100644 --- a/mdk-stage1/directory.c +++ b/mdk-stage1/directory.c @@ -45,78 +45,85 @@ char * extract_list_directory(char * direct) return strdup(tmp); } -enum return_type try_with_directory(char *directory, char *method_live, char *method_iso) { - char location_full[500]; - char * loopdev = NULL; - struct stat statbuf; +static enum return_type choose_iso_in_directory(char *directory, char *location_full) +{ + char **file; + char *stage2_isos[100] = { "Use directory as a mirror tree", "-----" }; + int stage2_iso_number = 2; - unlink(IMAGE_LOCATION); - strcpy(location_full, directory); + log_message("\"%s\" exists and is a directory, looking for iso files", directory); -#ifndef MANDRAKE_MOVE - if (!stat(directory, &statbuf) && S_ISDIR(statbuf.st_mode)) { - char **file; - char *stage2_isos[100] = { "Use directory as a mirror tree", "-----" }; - int stage2_iso_number = 2; + for (file = list_directory(directory); *file; file++) { + char isofile[500]; + char * loopdev = NULL; - log_message("\"%s\" exists and is a directory, looking for iso files", directory); + if (strstr(*file, ".iso") != *file + strlen(*file) - 4) + /* file doesn't end in .iso, skipping */ + continue; + + strcpy(isofile, directory); + strcat(isofile, "/"); + strcat(isofile, *file); - for (file = list_directory(directory); *file; file++) { - char isofile[500]; + if (lomount(isofile, IMAGE_LOCATION, &loopdev, 0)) { + log_message("unable to mount iso file \"%s\", skipping", isofile); + continue; + } - if (strstr(*file, ".iso") != *file + strlen(*file) - 4) - /* file doesn't end in .iso, skipping */ - continue; - - strcpy(isofile, directory); - strcat(isofile, "/"); - strcat(isofile, *file); + if (image_has_stage2()) { + log_message("stage2 installer found in ISO image \"%s\"", isofile); + stage2_isos[stage2_iso_number++] = strdup(*file); + } else { + log_message("ISO image \"%s\" doesn't contain stage2 installer", isofile); + } - if (lomount(isofile, IMAGE_LOCATION, &loopdev, 0)) { - log_message("unable to mount iso file \"%s\", skipping", isofile); - continue; - } + umount(IMAGE_LOCATION); + del_loop(loopdev); + } - if (image_has_stage2()) { - log_message("stage2 installer found in ISO image \"%s\"", isofile); - stage2_isos[stage2_iso_number++] = strdup(*file); - } else { - log_message("ISO image \"%s\" doesn't contain stage2 installer", isofile); + stage2_isos[stage2_iso_number] = NULL; + + if (stage2_iso_number > 2) { + enum return_type results; + do { + results = ask_from_list("Please choose the ISO image to be used to install the " + DISTRIB_NAME " Distribution.", + stage2_isos, file); + if (results == RETURN_BACK) { + return RETURN_BACK; + } else if (results == RETURN_OK) { + if (!strcmp(*file, stage2_isos[0])) { + /* use directory as a mirror tree */ + continue; + } else if (!strcmp(*file, stage2_isos[1])) { + /* the separator has been selected */ + results = RETURN_ERROR; + continue; + } else { + /* use selected ISO image */ + strcat(location_full, "/"); + strcat(location_full, *file); + log_message("installer will use ISO image \"%s\"", location_full); + } } + } while (results == RETURN_ERROR); + } else { + log_message("no ISO image found in \"%s\" directory", location_full); + } +} - umount(IMAGE_LOCATION); - del_loop(loopdev); - } - stage2_isos[stage2_iso_number] = NULL; - - if (stage2_iso_number > 2) { - enum return_type results; - do { - results = ask_from_list("Please choose the ISO image to be used to install the " - DISTRIB_NAME " Distribution.", - stage2_isos, file); - if (results == RETURN_BACK) { - return RETURN_BACK; - } else if (results == RETURN_OK) { - if (!strcmp(*file, stage2_isos[0])) { - /* use directory as a mirror tree */ - continue; - } else if (!strcmp(*file, stage2_isos[1])) { - /* the separator has been selected */ - results = RETURN_ERROR; - continue; - } else { - /* use selected ISO image */ - strcat(location_full, "/"); - strcat(location_full, *file); - log_message("installer will use ISO image \"%s\"", location_full); - } - } - } while (results == RETURN_ERROR); - } else { - log_message("no ISO image found in \"%s\" directory", location_full); - } +enum return_type try_with_directory(char *directory, char *method_live, char *method_iso) { + char location_full[500]; + char * loopdev = NULL; + struct stat statbuf; + + unlink(IMAGE_LOCATION); + strcpy(location_full, directory); + +#ifndef MANDRAKE_MOVE + if (!stat(directory, &statbuf) && S_ISDIR(statbuf.st_mode)) { + choose_iso_in_directory(directory, location_full); } #endif -- cgit v1.2.1