📄 extract_list.c
字号:
} amfree(regex); amfree(uqglob);}voiddelete_regex( char * regex){ char *s; char *uqregex = unquote_string(regex); if ((s = validate_regexp(regex)) != NULL) { g_printf(_("\"%s\" is not a valid regular expression: "), regex); puts(s); } else { delete_file(uqregex, uqregex); } amfree(uqregex);}voiddelete_file( char * path, char * regex){ DIR_ITEM *ditem, lditem; char *path_on_disk = NULL; char *cmd = NULL; char *err = NULL; int i; ssize_t j; char *date; char *tape, *tape_undo, tape_undo_ch = '\0'; char *dir_undo, dir_undo_ch = '\0'; int level = 0; off_t fileno; char *ditem_path = NULL; char *qditem_path; char *l = NULL; int deleted; char *s; int ch; int found_one; char *quoted; if (disk_path == NULL) { g_printf(_("Must select directory before deleting files\n")); return; } memset(&lditem, 0, sizeof(lditem)); /* Prevent use of bogus data... */ dbprintf(_("delete_file: Looking for \"%s\"\n"), path); if (strcmp(regex, "[^/]*[/]*$") == 0) { /* Looking for * find everything but single . */ regex = "([^/.]|\\.[^/]+|[^/.][^/]*)[/]*$"; } else { /* remove "/" at end of path */ j = (ssize_t)(strlen(regex) - 1); while(j >= 0 && regex[j] == '/') regex[j--] = '\0'; } /* convert path (assumed in cwd) to one on disk */ if (strcmp(disk_path, "/") == 0) { if (*regex == '/') { if (strcmp(regex, "/[/]*$") == 0) { /* We want "/" to match the directory itself: "/." */ path_on_disk = stralloc("/\\.[/]*$"); } else { /* No mods needed if already starts with '/' */ path_on_disk = stralloc(regex); } } else { /* Prepend '/' */ path_on_disk = stralloc2("/", regex); } } else { char *clean_disk_path = clean_regex(disk_path); path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL); amfree(clean_disk_path); } dbprintf(_("delete_file: Converted path=\"%s\" to path_on_disk=\"%s\"\n"), regex, path_on_disk); found_one = 0; for (ditem=get_dir_list(); ditem!=NULL; ditem=get_next_dir_item(ditem)) { quoted = quote_string(ditem->path); dbprintf(_("delete_file: Pondering ditem->path=%s\n"), quoted); amfree(quoted); if (match(path_on_disk, ditem->path)) { found_one = 1; j = (ssize_t)strlen(ditem->path); if((j > 0 && ditem->path[j-1] == '/') || (j > 1 && ditem->path[j-2] == '/' && ditem->path[j-1] == '.')) { /* It is a directory */ ditem_path = newstralloc(ditem_path, ditem->path); clean_pathname(ditem_path); qditem_path = quote_string(ditem_path); cmd = newstralloc2(cmd, "ORLD ", qditem_path); amfree(qditem_path); if(send_command(cmd) == -1) { amfree(cmd); amfree(ditem_path); amfree(path_on_disk); exit(1); } amfree(cmd); /* skip preamble */ if ((i = get_reply_line()) == -1) { amfree(ditem_path); amfree(path_on_disk); exit(1); } if(i==0) /* assume something wrong */ { amfree(ditem_path); amfree(path_on_disk); l = reply_line(); g_printf("%s\n", l); return; } deleted=0; lditem.path = newstralloc(lditem.path, ditem->path); amfree(cmd); tape_undo = dir_undo = NULL; /* skip the last line -- duplicate of the preamble */ while ((i = get_reply_line()) != 0) { if (i == -1) { amfree(ditem_path); amfree(path_on_disk); exit(1); } if(err) { if(cmd == NULL) { if(tape_undo) *tape_undo = tape_undo_ch; if(dir_undo) *dir_undo = dir_undo_ch; tape_undo = dir_undo = NULL; cmd = stralloc(l); /* save for the error report */ } continue; /* throw the rest of the lines away */ } l=reply_line(); if (!server_happy()) { puts(l); continue; } s = l; if(strncmp_const_skip(l, "201-", s, ch) != 0) { err = _("bad reply: not 201-"); continue; } ch = *s++; skip_whitespace(s, ch); if(ch == '\0') { err = _("bad reply: missing date field"); continue; } date = s - 1; skip_non_whitespace(s, ch); *(s - 1) = '\0'; skip_whitespace(s, ch); if(ch == '\0' || sscanf(s - 1, "%d", &level) != 1) { err = _("bad reply: cannot parse level field"); continue; } skip_integer(s, ch); skip_whitespace(s, ch); if(ch == '\0') { err = _("bad reply: missing tape field"); continue; } tape = s - 1; skip_non_whitespace(s, ch); tape_undo = s - 1; tape_undo_ch = *tape_undo; *tape_undo = '\0'; if(am_has_feature(indexsrv_features, fe_amindexd_fileno_in_ORLD)) { long long fileno_ = (long long)0; skip_whitespace(s, ch); if(ch == '\0' || sscanf(s - 1, "%lld", &fileno_) != 1) { err = _("bad reply: cannot parse fileno field"); continue; } fileno = (off_t)fileno_; skip_integer(s, ch); } skip_whitespace(s, ch); if(ch == '\0') { err = _("bad reply: missing directory field"); continue; } skip_non_whitespace(s, ch); dir_undo = s - 1; dir_undo_ch = *dir_undo; *dir_undo = '\0'; lditem.date = newstralloc(lditem.date, date); lditem.level=level; lditem.tape = newstralloc(lditem.tape, tape); switch(delete_extract_item(&lditem)) { case -1: g_printf(_("System error\n")); dbprintf(_("delete_file: (Failed) System error\n")); break; case 0: g_printf(_("Deleted dir %s at date %s\n"), ditem_path, date); dbprintf(_("delete_file: (Successful) Deleted dir %s at date %s\n"), ditem_path, date); deleted=1; break; case 1: break; } } if(!server_happy()) { puts(reply_line()); } else if(err) { if (*err) puts(err); if (cmd) puts(cmd); } else if(deleted == 0) { g_printf(_("Warning - dir '%s' not on tape list\n"), ditem_path); dbprintf(_("delete_file: dir '%s' not on tape list\n"), ditem_path); } } else { switch(delete_extract_item(ditem)) { case -1: g_printf(_("System error\n")); dbprintf(_("delete_file: (Failed) System error\n")); break; case 0: g_printf(_("Deleted %s\n"), ditem->path); dbprintf(_("delete_file: (Successful) Deleted %s\n"), ditem->path); break; case 1: g_printf(_("Warning - file '%s' not on tape list\n"), ditem->path); dbprintf(_("delete_file: file '%s' not on tape list\n"), ditem->path); break; } } } } amfree(cmd); amfree(ditem_path); amfree(path_on_disk); if(! found_one) { g_printf(_("File %s doesn't exist in directory\n"), path); dbprintf(_("delete_file: (Failed) File %s doesn't exist in directory\n"), path); }}/* print extract list into file. If NULL ptr passed print to screen */voiddisplay_extract_list( char * file){ EXTRACT_LIST *this; EXTRACT_LIST_ITEM *that; FILE *fp; char *pager; char *pager_command; char *uqfile; if (file == NULL) { if ((pager = getenv("PAGER")) == NULL) { pager = "more"; } /* * Set up the pager command so if the pager is terminated, we do * not get a SIGPIPE back. */ pager_command = stralloc2(pager, " ; /bin/cat > /dev/null"); if ((fp = popen(pager_command, "w")) == NULL) { g_printf(_("Warning - can't pipe through %s\n"), pager); fp = stdout; } amfree(pager_command); } else { uqfile = unquote_string(file); if ((fp = fopen(uqfile, "w")) == NULL) { g_printf(_("Can't open file %s to print extract list into\n"), file); amfree(uqfile); return; } amfree(uqfile); } for (this = extract_list; this != NULL; this = this->next) { g_fprintf(fp, _("TAPE %s LEVEL %d DATE %s\n"), this->tape, this->level, this->date); for (that = this->files; that != NULL; that = that->next) g_fprintf(fp, "\t%s\n", that->path); } if (file == NULL) { apclose(fp); } else { g_printf(_("Extract list written to file %s\n"), file); afclose(fp); }}static intis_empty_dir( char *fname){ DIR *dir; struct dirent *entry; int gotentry; if((dir = opendir(fname)) == NULL) return 1; gotentry = 0; while(!gotentry && (entry = readdir(dir)) != NULL) { gotentry = !is_dot_or_dotdot(entry->d_name); } closedir(dir); return !gotentry;}/* returns 0 if extract list empty and 1 if it isn't */intis_extract_list_nonempty(void){ return (extract_list != NULL);}/* prints continue prompt and waits for response, returns 0 if don't, non-0 if do */static intokay_to_continue( int allow_tape, int allow_skip, int allow_retry){ int ch; int ret = -1; char *line = NULL; char *s; char *prompt; int get_device; get_device = 0; while (ret < 0) { if (get_device) { prompt = _("New device name [?]: "); } else if (allow_tape && allow_skip) { prompt = _("Continue [?/Y/n/s/d]? "); } else if (allow_tape && !allow_skip) { prompt = _("Continue [?/Y/n/d]? "); } else if (allow_retry) { prompt = _("Continue [?/Y/n/r]? "); } else { prompt = _("Continue [?/Y/n]? "); } fputs(prompt, stdout); fflush(stdout); fflush(stderr); amfree(line); if ((line = agets(stdin)) == NULL) { putchar('\n'); clearerr(stdin); if (get_device) { get_device = 0; continue; } ret = 0; break; } dbprintf("User prompt: '%s'; response: '%s'\n", prompt, line); s = line; while ((ch = *s++) != '\0' && isspace(ch)) { (void)ch; /* Quiet empty loop compiler warning */ } if (ch == '?') { if (get_device) { g_printf(_("Enter a new device name or \"default\"\n")); } else { g_printf(_("Enter \"y\"es to continue, \"n\"o to stop")); if(allow_skip) { g_printf(_(", \"s\"kip this tape")); } if(allow_retry) { g_printf(_(" or \"r\"etry this tape")); } if (allow_tape) { g_printf(_(" or \"d\" to change to a new device")); } putchar('\n'); } } else if (get_device) { char *tmp = stralloc(tape_server_name); if (strncmp_const(s - 1, "default") == 0) { set_device(tmp, NULL); /* default device, existing host */ } else if (s[-1] != '\0') { set_device(tmp, s - 1); /* specified device, existing host */ } else { g_printf(_("No change.\n")); } amfree(tmp); get_device = 0; } else if (ch == '\0' || ch == 'Y' || ch == 'y') { ret = 1; } else if (allow_tape && (ch == 'D' || ch == 'd' || ch == 'T' || ch == 't')) { get_device = 1; /* ('T' and 't' are for backward-compatibility) */ } else if (ch == 'N' || ch == 'n') { ret = 0; } else if (allow_retry && (ch == 'R' || ch == 'r')) { ret = RETRY_TAPE; } else if (allow_skip && (ch == 'S' || ch == 's')) { ret = SKIP_TAPE; } } /*@ignore@*/ amfree(line); /*@end@*/ return ret;}static voidsend_to_tape_server( security_stream_t * stream, char * cmd){ char *msg = stralloc2(cmd, "\r\n"); if (security_stream_write(stream, msg, strlen(msg)) < 0) { error(_("Error writing to tape server")); exit(101); /*NOTREACHED*/ } amfree(msg);}/* start up connection to tape server and set commands to initiate transfer of dump image. Return tape server socket on success, -1 on error. */static intextract_files_setup( char * label, off_t fsf){ char *disk_regex = NULL; char *host_regex = NULL; char *clean_datestamp, *ch, *ch1; char *tt = NULL; char *req; int response_error; amidxtaped_secdrv = security_getdriver(authopt); if (amidxtaped_secdrv == NULL) { error(_("no '%s' security driver available for host '%s'"), authopt, tape_server_name); } /* We assume that amidxtaped support fe_amidxtaped_options_features */ /* and fe_amidxtaped_options_auth */ /* We should send a noop to really know */ req = vstralloc("SERVICE amidxtaped\n", "OPTIONS ", "features=", our_features_string, ";", "auth=", authopt, ";", "\n", NULL); protocol_sendreq(tape_server_name, amidxtaped_secdrv, generic_client_get_security_conf, req, STARTUP_TIMEOUT, amidxtaped_response, &response_error); amfree(req); protocol_run(); if(response_error != 0) { return -1; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -