version 1.117, 2004/01/29 08:48:23 |
version 1.118, 2004/04/18 20:42:19 |
Line 758 extract_dist(void) |
|
Line 758 extract_dist(void) |
|
tarstats.nskipped++; |
tarstats.nskipped++; |
continue; |
continue; |
} |
} |
#if 0 |
|
if (cleanup_dist(list->name) == 0) { |
|
msg_display(MSG_cleanup_warn); |
|
process_menu(MENU_ok, NULL); |
|
} |
|
#endif |
|
(void)snprintf(fname, sizeof fname, "%s/%s%s", |
(void)snprintf(fname, sizeof fname, "%s/%s%s", |
ext_dir, list->name, dist_postfix); |
ext_dir, list->name, dist_postfix); |
|
|
Line 791 extract_dist(void) |
|
Line 785 extract_dist(void) |
|
return extracted == 0; |
return extracted == 0; |
} |
} |
|
|
#if 0 /* { NOMORE */ |
|
|
|
/* |
|
* Do pre-extract cleanup for set 'name': |
|
* open a file named '/var/db/obsolete/<name>', 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 renamed to <directory.old>. |
|
*/ |
|
|
|
/* definition for a list of files. */ |
|
struct filelist { |
|
struct filelist *next; |
|
char name[MAXPATHLEN]; |
|
mode_t type; |
|
}; |
|
|
|
int |
|
cleanup_dist(const char *name) |
|
{ |
|
char file_path[MAXPATHLEN]; |
|
char file_name[MAXPATHLEN]; |
|
const char *file_prefix; |
|
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, "/var/db/obsolete/%s", name); |
|
list_file = fopen(file_path, "r"); |
|
if (list_file == NULL) { |
|
saved_errno = errno; |
|
if (logging) |
|
fprintf(logfp, "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, NULL); |
|
return 0; |
|
} |
|
file_prefix = target_prefix(); |
|
while (fgets(file_name, MAXPATHLEN, list_file)) { |
|
/* 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", file_prefix, |
|
file_name); |
|
if (lstat(file_path, &st) != 0) { |
|
saved_errno = errno; |
|
if (logging) |
|
fprintf(logfp, "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, NULL); |
|
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 (current->next == 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(logfp, "Adding file %s, type %d to list of " |
|
"obsolete file\n", current->name, current->type); |
|
} |
|
fclose(list_file); |
|
if (head == NULL) |
|
return 1; |
|
#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) { |
|
/* XXX msg_printf_add going/gone away */ |
|
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) { |
|
/* XXX msg_printf_add going/gone away */ |
|
msg_printf_add("%s ", current->name); |
|
} |
|
} |
|
process_menu(MENU_ok, NULL); |
|
#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 (saved_errno == ENOENT) |
|
continue; /* don't worry about |
|
non-existing files */ |
|
if (logging) |
|
fprintf(logfp, "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(logfp, "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(logfp, "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 */ |
|
/* |
|
* Don't worry about non-existing directories. |
|
*/ |
|
if (saved_errno == ENOENT) |
|
continue; |
|
if (logging) |
|
fprintf(logfp, "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, NULL); |
|
return retval; |
|
} |
|
#endif /* } NOMORE */ |
|
|
|
/* |
/* |
* Get and unpack the distribution. |
* Get and unpack the distribution. |
* Show success_msg if installation completes. |
* Show success_msg if installation completes. |