Main change: add a cleanup_dist() function in util.c which will do the needed
cleanups before extracting a set. Should'nt do anything for an install, as the filesystem shouldn't contain files that need to be removed. cleanup_dist() is called before extract_file() for each set (the set name is passed as parameter). It will open a file /dist/<set name>_obsolete if it exists. This file should contain a list of files (absolutes pathnames) that needs to be removed. cleanup_dist() will lstat() each file to determine if it's there and if it's a directory or not. It will then unlink() entries that are not directories and then rmdir() directories. If a directory is not empty (it should now if the list of files is correct) it will be renamed to <directory.old> and the user will be warned. Other changes: - move prototype of target_prefix() in defs.h, don't maintain a copy of it in each file. - in install.c, after MSG_disksetupdone, do a wclear(stdscr) (display was clobbered after it). - kill MSG_openmsgbuf, it's not used anywhere - after MSG_disksetupdone in upgrade, don't call MENU_ok, do it the same way as in install. - add wclear(stdscr);/wrefresh(stdscr); before calling MENU_distset (another display problem ...) - While I'm there, move ask_verbose_dist() before MENU_distmedium. This way, if all go well the user can go away one ftp starts and come back once sets are extracted.
This commit is contained in:
parent
51ec3af2ba
commit
8d7cb08335
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: defs.h,v 1.39 1999/04/11 22:40:19 bouyer Exp $ */
|
||||
/* $NetBSD: defs.h,v 1.40 1999/04/13 20:17:47 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -308,6 +308,7 @@ void append_to_target_file __P((const char *path, const char *string));
|
||||
void echo_to_target_file __P(( const char *path, const char *string));
|
||||
void sprintf_to_target_file __P(( const char *path, const char *fmt, ...));
|
||||
void trunc_target_file __P((const char *path));
|
||||
const char* target_prefix __P((void));
|
||||
int target_chdir __P(( const char *path));
|
||||
void target_chdir_or_die __P((const char *dir));
|
||||
int target_already_root __P((void));
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: disks.c,v 1.25 1999/04/11 22:40:19 bouyer Exp $ */
|
||||
/* $NetBSD: disks.c,v 1.26 1999/04/13 20:17:47 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -70,9 +70,6 @@ static int fsck_with_error_menu(const char *diskpart);
|
||||
static int target_mount_with_error_menu(const char *opt, char *diskpart,
|
||||
const char *mntpt);
|
||||
|
||||
/* external */
|
||||
const char* target_prefix __P((void));
|
||||
|
||||
|
||||
static void get_disks(void)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: install.c,v 1.15 1999/04/11 22:40:20 bouyer Exp $ */
|
||||
/* $NetBSD: install.c,v 1.16 1999/04/13 20:17:47 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -118,6 +118,7 @@ do_install()
|
||||
|
||||
getchar();
|
||||
puts(CL); /* just to make sure */
|
||||
wclear(stdscr);
|
||||
wrefresh(stdscr);
|
||||
|
||||
/* Unpack the distribution. */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: msg.mi.eng,v 1.39 1999/04/13 14:49:56 bouyer Exp $ */
|
||||
/* $NetBSD: msg.mi.eng,v 1.40 1999/04/13 20:17:47 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -255,6 +255,39 @@ If the target filesystems look good, the next step is to fetch and
|
||||
unpack the distribution filesets. Press <return> to proceed.
|
||||
}
|
||||
|
||||
message openfail
|
||||
{Could not open %s, error message was: %s.
|
||||
}
|
||||
|
||||
message statfail
|
||||
{Can't get properties of %s, error message was: %s.
|
||||
}
|
||||
|
||||
message unlink_fail
|
||||
{I was unable to delete %s, error message was: %s.
|
||||
}
|
||||
|
||||
message rename_fail
|
||||
{I was unable to rename %s to %s, error message was: %s.
|
||||
}
|
||||
|
||||
message deleting_files
|
||||
{As part of the upgrade procedure, the following have to be deleted:
|
||||
}
|
||||
|
||||
message deleting_dirs
|
||||
{As part of the upgrade procedure, the following directories have to be
|
||||
deleted (I will rename those that are not empty):
|
||||
}
|
||||
|
||||
message renamed_dir
|
||||
{The directory %s has been renamed to %s because it was not empty.
|
||||
}
|
||||
|
||||
message cleanup_warn
|
||||
{Cleanup of the existing install failed. This may cause cause the extraction
|
||||
of the set to fail.
|
||||
}
|
||||
|
||||
message nomount
|
||||
{Partition %c's type is not 4.2BSD or msdos and therefore does not have
|
||||
@ -522,10 +555,6 @@ proceed by hand, or choose a different source for release sets and try
|
||||
again.
|
||||
}
|
||||
|
||||
message openmsgbuf
|
||||
{Could not open /kern/msgbuf.
|
||||
}
|
||||
|
||||
message anonprog
|
||||
{sysinst: running "%s"
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: msg.mi.fr,v 1.16 1999/04/13 14:49:56 bouyer Exp $ */
|
||||
/* $NetBSD: msg.mi.fr,v 1.17 1999/04/13 20:17:47 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -259,6 +259,43 @@ Si les syst
|
||||
recopier les différents composants. Appuyer sur <entrée> pour continuer.
|
||||
}
|
||||
|
||||
message openfail
|
||||
{Je n'ai pas pu ouvrir %s, le message d'erreur était: %s.
|
||||
}
|
||||
|
||||
message statfail
|
||||
{Je n'ai pas pu avoir les propriétées de %s, le message d'erreur
|
||||
etait: %s.
|
||||
}
|
||||
|
||||
message unlink_fail
|
||||
{Je n'ai pas pu effacer %s, le message d'erreur était: %s.
|
||||
}
|
||||
|
||||
message rename_fail
|
||||
{je n'ai pas pu renomer %s en %s, le message d'erreur était: %s.
|
||||
}
|
||||
|
||||
message deleting_files
|
||||
{Pour la procédure de mise à jour, les fichiers suivant doivent etre
|
||||
supprimés:
|
||||
}
|
||||
|
||||
message deleting_dirs
|
||||
{Pour la procédude de mise à jour, les répertoires suivants doivent
|
||||
etre supprimés (je renomerais ceux qui ne sont pas vides):
|
||||
}
|
||||
|
||||
message renamed_dir
|
||||
{Le répertoire %s a été renomé en %s.
|
||||
}
|
||||
|
||||
message cleanup_warn
|
||||
{Les ajustements nécessaire à la mise à niveau de l'installation
|
||||
existante ont échouées. Cela peut empêcher l'extraction du composant
|
||||
suivant.
|
||||
}
|
||||
|
||||
message nomount
|
||||
{La partition %c n'est ni 4.2BSD, ni msdos c'est pour cela qu'elle n'a pas de
|
||||
point de montage.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: net.c,v 1.43 1999/04/13 14:49:56 bouyer Exp $ */
|
||||
/* $NetBSD: net.c,v 1.44 1999/04/13 20:17:48 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -63,9 +63,6 @@ static char *url_encode __P((char *dst, const char *src, size_t len,
|
||||
static void get_ifconfig_info __P((void));
|
||||
static void get_ifinterface_info __P((void));
|
||||
|
||||
/* external */
|
||||
const char* target_prefix __P((void));
|
||||
|
||||
/*
|
||||
* URL encode unsafe characters. See RFC 1738.
|
||||
*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: target.c,v 1.20 1999/04/09 10:24:39 bouyer Exp $ */
|
||||
/* $NetBSD: target.c,v 1.21 1999/04/13 20:17:48 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Jonathan Stone
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: target.c,v 1.20 1999/04/09 10:24:39 bouyer Exp $");
|
||||
__RCSID("$NetBSD: target.c,v 1.21 1999/04/13 20:17:48 bouyer Exp $");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -74,7 +74,6 @@ int target_on_current_disk __P((void));
|
||||
int must_mount_root __P((void));
|
||||
|
||||
static void make_prefixed_dir __P((const char *prefix, const char *path));
|
||||
const char* target_prefix __P((void));
|
||||
static int do_target_chdir __P((const char *dir, int flag));
|
||||
static const char* concat_paths __P((const char *prefix, const char *suffix));
|
||||
int target_test(const char *test, const char *path);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: upgrade.c,v 1.16 1998/11/16 02:28:13 simonb Exp $ */
|
||||
/* $NetBSD: upgrade.c,v 1.17 1999/04/13 20:17:48 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -96,7 +96,10 @@ do_upgrade()
|
||||
|
||||
/* Done with disks. Ready to get and unpack tarballs. */
|
||||
msg_display(MSG_disksetupdone);
|
||||
process_menu(MENU_ok);
|
||||
getchar();
|
||||
puts(CL); /* just to make sure */
|
||||
wclear(stdscr);
|
||||
wrefresh(stdscr);
|
||||
|
||||
get_and_unpack_sets(MSG_upgrcomplete, MSG_abortupgr);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: util.c,v 1.36 1999/04/11 22:40:22 bouyer Exp $ */
|
||||
/* $NetBSD: util.c,v 1.37 1999/04/13 20:17:48 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Piermont Information Systems Inc.
|
||||
@ -46,6 +46,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <curses.h>
|
||||
#include <errno.h>
|
||||
#include "defs.h"
|
||||
#include "md.h"
|
||||
#include "msg_defs.h"
|
||||
@ -64,6 +65,7 @@ struct tarstats {
|
||||
|
||||
void extract_file __P((char *path));
|
||||
int extract_dist __P((void));
|
||||
int cleanup_dist __P((const char *path));
|
||||
int distribution_sets_exist_p __P((const char *path));
|
||||
static int check_for __P((const char *type, const char *pathname));
|
||||
|
||||
@ -502,7 +504,7 @@ extract_file(path)
|
||||
|
||||
|
||||
/*
|
||||
* Extract_dist **REQUIRES** an absolute path in ext_dir. Any code
|
||||
* Extract_dist **REQUIRES** an absolute path in ext_dir. Any code
|
||||
* that sets up dist_dir for use by extract_dist needs to put in the
|
||||
* full path name to the directory.
|
||||
*/
|
||||
@ -522,6 +524,10 @@ extract_dist()
|
||||
while (list->name) {
|
||||
if (list->getit) {
|
||||
tarstats.nselected++;
|
||||
if (cleanup_dist(list->name) == 0) {
|
||||
msg_display(MSG_cleanup_warn);
|
||||
process_menu(MENU_ok);
|
||||
}
|
||||
(void)snprintf(distname, STRSIZE, "%s%s", list->name,
|
||||
dist_postfix);
|
||||
(void)snprintf(fname, STRSIZE, "%s/%s", ext_dir,
|
||||
@ -548,6 +554,174 @@ extract_dist()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Do pre-extract cleanup for set 'name':
|
||||
* open a file named '/dist/<name>_obsolete file', which contain a list of
|
||||
* files to kill from the target. For each file, test if it is present on
|
||||
* the target. Then display the list of files which will be removed,
|
||||
* ask user for confirmation, and process.
|
||||
* Non-empty directories will be renaned to <directory.old>.
|
||||
*/
|
||||
|
||||
/* definition for a list of files. */
|
||||
struct filelist {
|
||||
struct filelist *next;
|
||||
char name[MAXPATHLEN];
|
||||
mode_t type;
|
||||
};
|
||||
|
||||
int
|
||||
cleanup_dist(name)
|
||||
const char *name;
|
||||
{
|
||||
char file_path[MAXPATHLEN];
|
||||
char file_name[MAXPATHLEN];
|
||||
FILE *list_file;
|
||||
struct filelist *head = NULL;
|
||||
struct filelist *current;
|
||||
int saved_errno;
|
||||
struct stat st;
|
||||
int retval = 1;
|
||||
int needok = 0;
|
||||
|
||||
snprintf(file_path, MAXPATHLEN, "/dist/%s_obsolete", name);
|
||||
list_file = fopen(file_path, "r");
|
||||
if (list_file == NULL) {
|
||||
saved_errno = errno;
|
||||
if (logging)
|
||||
fprintf(log, "Open of %s failed: %s\n", file_path,
|
||||
strerror(saved_errno));
|
||||
if (saved_errno == ENOENT)
|
||||
return 1;
|
||||
msg_display_add(MSG_openfail, name, strerror(saved_errno));
|
||||
process_menu(MENU_ok);
|
||||
return 0;
|
||||
}
|
||||
while (fgets(file_name, MAXPATHLEN, list_file)) {
|
||||
/* ignore lines that don't begin with '/' */
|
||||
if (file_name[0] != '/')
|
||||
continue;
|
||||
/* Remove trailing \n if any */
|
||||
if (file_name[strlen(file_name)-1] == '\n')
|
||||
file_name[strlen(file_name)-1] = '\0';
|
||||
snprintf(file_path, MAXPATHLEN, "%s%s", target_prefix(),
|
||||
file_name);
|
||||
if (lstat(file_path, &st) != 0) {
|
||||
saved_errno = errno;
|
||||
if (logging)
|
||||
fprintf(log, "stat() of %s failed: %s\n",
|
||||
file_path, strerror(saved_errno));
|
||||
if (saved_errno == ENOENT)
|
||||
continue;
|
||||
msg_display_add(MSG_statfail, file_path,
|
||||
strerror(saved_errno));
|
||||
process_menu(MENU_ok);
|
||||
return 0;
|
||||
}
|
||||
if (head == NULL) {
|
||||
head = current = malloc(sizeof(struct filelist));
|
||||
if (head == NULL) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
current->next = malloc(sizeof(struct filelist));
|
||||
if (head == NULL) {
|
||||
fprintf(stderr, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
current = current->next;
|
||||
}
|
||||
current->next = NULL;
|
||||
snprintf(current->name, MAXPATHLEN, "%s", file_path);
|
||||
current->type = st.st_mode & S_IFMT;
|
||||
if (logging)
|
||||
fprintf(log, "Adding file %s, type %d to list of "
|
||||
"obsolete file\n", current->name, current->type);
|
||||
}
|
||||
if (head == NULL)
|
||||
return 0;
|
||||
#if 0
|
||||
/* XXX doesn't work, too many files printed ! */
|
||||
msg_display(MSG_deleting_files);
|
||||
for (current = head; current != NULL; current = current->next) {
|
||||
if (current->type != S_IFDIR)
|
||||
msg_printf_add("%s ", current->name);
|
||||
}
|
||||
msg_display_add(MSG_deleting_dirs);
|
||||
for (current = head; current != NULL; current = current->next) {
|
||||
if (current->type == S_IFDIR)
|
||||
msg_printf_add("%s ", current->name);
|
||||
}
|
||||
process_menu(MENU_ok);
|
||||
#endif
|
||||
/* first remove files */
|
||||
for (current = head; current != NULL; current = current->next) {
|
||||
if (current->type == S_IFDIR)
|
||||
continue;
|
||||
if (scripting)
|
||||
(void)fprintf(script, "rm %s\n", current->name);
|
||||
if (unlink(current->name) != 0) {
|
||||
saved_errno = errno;
|
||||
if (logging)
|
||||
fprintf(log, "rm %s failed: %s\n",
|
||||
current->name, strerror(saved_errno));
|
||||
msg_display_add(MSG_unlink_fail, current->name,
|
||||
strerror(saved_errno));
|
||||
retval = 0;
|
||||
needok = 1;
|
||||
}
|
||||
|
||||
}
|
||||
/* now dirs */
|
||||
for (current = head; current != NULL; current = current->next) {
|
||||
if (current->type != S_IFDIR)
|
||||
continue;
|
||||
if (rmdir(current->name) == 0) {
|
||||
if (scripting)
|
||||
(void)fprintf(script, "rmdir %s\n",
|
||||
current->name);
|
||||
continue;
|
||||
}
|
||||
saved_errno = errno;
|
||||
if (saved_errno == ENOTEMPTY) {
|
||||
if (logging)
|
||||
fprintf(log, "dir %s not empty, "
|
||||
"trying to rename to %s.old\n",
|
||||
current->name, current->name);
|
||||
snprintf(file_path, MAXPATHLEN,
|
||||
"%s.old", current->name);
|
||||
if (scripting)
|
||||
(void)fprintf(script, "mv %s %s\n",
|
||||
current->name, file_path);
|
||||
needok = 1;
|
||||
if (rename(current->name, file_path) != 0) {
|
||||
saved_errno = errno;
|
||||
if (logging)
|
||||
fprintf(log, "mv %s %s failed: %s\n",
|
||||
current->name, file_path,
|
||||
strerror(saved_errno));
|
||||
msg_display_add(MSG_rename_fail, current->name,
|
||||
file_path, strerror(errno));
|
||||
retval = 0;
|
||||
}
|
||||
msg_display_add(MSG_renamed_dir, current->name,
|
||||
file_path);
|
||||
} else { /* rmdir error */
|
||||
if (logging)
|
||||
fprintf(log, "rm %s failed: %s\n",
|
||||
current->name, strerror(saved_errno));
|
||||
msg_display_add(MSG_unlink_fail, current->name,
|
||||
strerror(saved_errno));
|
||||
retval = 0;
|
||||
needok = 1;
|
||||
}
|
||||
}
|
||||
if (needok)
|
||||
process_menu(MENU_ok);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get and unpack the distribution.
|
||||
* show success_msg if installation completes. Otherwise,,
|
||||
@ -566,8 +740,13 @@ get_and_unpack_sets(success_msg, failure_msg)
|
||||
(void)fprintf(script, "mkdir /mnt2\nchmod 755 /mnt2\n");
|
||||
|
||||
/* Find out which files to "get" if we get files. */
|
||||
wclear(stdscr);
|
||||
wrefresh(stdscr);
|
||||
process_menu(MENU_distset);
|
||||
|
||||
/* ask user whether to do normal or verbose extraction */
|
||||
ask_verbose_dist();
|
||||
|
||||
/* Get the distribution files */
|
||||
process_menu(MENU_distmedium);
|
||||
|
||||
@ -576,9 +755,6 @@ get_and_unpack_sets(success_msg, failure_msg)
|
||||
|
||||
if (got_dist) {
|
||||
|
||||
/* ask user whether to do normal or verbose extraction */
|
||||
ask_verbose_dist();
|
||||
|
||||
/* Extract the distribution, abort on errors. */
|
||||
if (extract_dist()) {
|
||||
goto bad;
|
||||
|
Loading…
Reference in New Issue
Block a user