Allowing to restore from image with pending changes

This commit is contained in:
2008-06-09 13:44:06 +00:00
parent daa98e8008
commit 25c4acaf79
6 changed files with 264 additions and 34 deletions

View File

@ -1457,18 +1457,21 @@ int Sregex_string(char **handle, char *text, int flag)
#endif /* Xorriso_sregex_externaL */
#ifndef Xorriso_text_shellsafe_externaL
/* @param flag bit0= append to out_text rather than overwrite it
*/
char *Text_shellsafe(char *in_text, char *out_text, int flag)
{
int l,i,w=0;
int l,i,ol= 0,w=0;
if(flag&1)
ol= w= strlen(out_text);
/* enclose everything by hard quotes */
l= strlen(in_text);
out_text[w++]= '\'';
for(i=0;i<l;i++){
if(in_text[i]=='\''){
if(w+7>5*SfileadrL)
if(w+7>5*SfileadrL+ol)
goto overflow;
/* escape hard quote within the text */
out_text[w++]= '\'';
@ -1491,11 +1494,6 @@ overflow:;
}
#endif /* ! Xorriso_text_shellsafe_externaL */
#ifndef Xorriso_fileliste_externaL
/* ??? ts A71006 : Is this compatible with mkisofs pathspecs ?
@ -2730,7 +2728,7 @@ int Permstack_pop(struct PermiteM **o, struct PermiteM *stopper,
/* don't complain if it fails */
if(!(flag&2)) {
utime_buffer.actime= m->stbuf.st_atime;
utime_buffer.modtime= m->stbuf.st_mtime;;
utime_buffer.modtime= m->stbuf.st_mtime;
ret= utime(m->disk_path,&utime_buffer);
if(ret==-1 && xorriso!=NULL) {
sprintf(xorriso->info_text,
@ -6364,6 +6362,59 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd,
}
/* @param flag bit0= path is a directory
bit2= recursion: do not reassure in mode 2 "tree"
bit3= this is for overwriting and not for plain removal
*/
int Xorriso_reassure_restore(struct XorrisO *xorriso, char *path, int flag)
{
int ret;
char sfe[5*SfileadrL];
while((xorriso->do_reassure==1 || (xorriso->do_reassure==2 && !(flag&4)))
&& !xorriso->request_not_to_ask) {
/* ls -ld */
Xorriso_lsx_filev(xorriso, xorriso->wdx, 1, &path, (off_t) 0, 1|2|8);
if(flag&1) /* du -s */
Xorriso_lsx_filev(xorriso, xorriso->wdx, 1, &path, (off_t) 0, 2|4);
if(flag&8)
sprintf(xorriso->info_text,
"File exists. Remove ? n= keep old, y= remove, x= abort, @= stop asking\n");
else
sprintf(xorriso->info_text,
"Remove above file ? n= keep it, y= remove it, x= abort, @= stop asking\n");
Xorriso_info(xorriso, 4);
ret= Xorriso_request_confirmation(xorriso, 1|2|4|16);
if(ret<=0)
goto ex;
if(xorriso->request_to_abort) {
sprintf(xorriso->info_text,
"Removal operation aborted by user before file: %s",
Text_shellsafe(path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
ret= 3; goto ex;
}
if(ret==3)
continue;
if(ret==6) /* yes */
break;
if(ret==4) { /* yes, do not ask again */
xorriso->request_not_to_ask= 1;
break;
}
if(ret==1) { /* no */
sprintf(xorriso->info_text, "Kept in existing state: %s",
Text_shellsafe(path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
ret= 3; goto ex;
}
}
ret= 1;
ex:
return(ret);
}
/*
@param flag >>> bit0= remove whole sub tree: rm -r
bit1= remove empty directory: rmdir
@ -6507,6 +6558,8 @@ dir_not_removed:;
if(xorriso->request_to_abort)
{ret= 3; goto ex;}
#ifdef NIX
while((xorriso->do_reassure==1 || (xorriso->do_reassure==2 && !(flag&4)))
&& !xorriso->request_not_to_ask) {
/* ls -ld */
@ -6545,6 +6598,15 @@ dir_not_removed:;
ret= 3; goto ex;
}
}
#else /* NIX */
ret= Xorriso_reassure_restore(xorriso, path, (flag&(4|8)) | !!is_dir);
if(ret<=0 || ret==3)
goto ex;
#endif /* ! NIX */
if(is_dir)
ret= rmdir(path);
else
@ -7834,6 +7896,31 @@ int Xorriso_path_is_excluded(struct XorrisO *xorriso, char *path, int flag)
return(ret);
}
int Xorriso_make_tmp_path(struct XorrisO *xorriso, char *orig_path,
char *tmp_path, int *fd, int flag)
{
char *cpt;
cpt= strrchr(orig_path, '/');
if(cpt==NULL)
tmp_path[0]= 0;
else {
strncpy(tmp_path, orig_path, cpt+1-orig_path);
tmp_path[cpt+1-orig_path]= 0;
}
strcat(tmp_path, "_tmp_xorriso_restore_XXXXXX");
*fd= mkstemp(tmp_path);
if(*fd==-1) {
strcpy(xorriso->info_text, "Cannot create temporary file : ");
Text_shellsafe(tmp_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
return(0);
}
fchmod(*fd, S_IRUSR|S_IWUSR);
return(1);
}
/* ---------------------------- Options API ------------------------ */
@ -8754,12 +8841,15 @@ int Xorriso_option_cpx(struct XorrisO *xorriso, int argc, char **argv,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
/* <<<
if(xorriso->volset_change_pending) {
sprintf(xorriso->info_text,
"-cp*x: Image changes pending. May not copy from image to disk.\n");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
*/
/* Perform copying */
Xorriso_pacifier_reset(xorriso, 0);
@ -8818,7 +8908,7 @@ problem_handler:;
goto ex;
}
if(xorriso->pacifier_count>0)
Xorriso_pacifier_callback(xorriso, "files copied", xorriso->pacifier_count,
Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count,
xorriso->pacifier_total, "", 1);
ret= !was_failure;
ex:;
@ -11685,7 +11775,7 @@ return:
#ifdef NIX
int arg_count;
#endif
char *cmd, *original_cmd, cmd_data[2*SfileadrL], *arg1, *arg2;
char *cmd, *original_cmd, cmd_data[2*SfileadrL], *arg1, *arg2, type_text[5];
if(xorriso==NULL)
return(0);
@ -12145,7 +12235,13 @@ next_command:;
ret= Xorriso_option_temp_mem_limit(xorriso, arg1, 0);
} else if(strcmp(cmd,"test")==0) { /* This option does not exist. */
;
(*idx)+= 2;
ret= Xorriso_restore_is_identical(xorriso, NULL, arg2, arg1, type_text, 2);
if(ret>=0) {
sprintf(xorriso->info_text, "ISO node and disk file are %s\n",
ret>0 ? ret==2 ? "suspicious" : "identical" : "different");
Xorriso_info(xorriso, 0);
}
} else if(strcmp(cmd,"toc")==0) {
Xorriso_option_toc(xorriso, 0);