Implemented option -reassure
This commit is contained in:
@ -43,6 +43,10 @@
|
||||
#include "xorrisoburn.h"
|
||||
|
||||
|
||||
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
|
||||
int flag);
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
@ -608,12 +612,12 @@ int Xorriso_add_tree(struct XorrisO *xorriso, struct iso_tree_node_dir *dir,
|
||||
|
||||
if(Sfile_str(disk_path, disk_dir_path,0)<=0)
|
||||
{ret= -1; goto ex;}
|
||||
if(disk_path[strlen(disk_path)-1]!='/')
|
||||
if(disk_path[0]==0 || disk_path[strlen(disk_path)-1]!='/')
|
||||
strcat(disk_path,"/");
|
||||
name= disk_path+strlen(disk_path);
|
||||
if(Sfile_str(img_path, img_dir_path, 0)<=0)
|
||||
{ret= -1; goto ex;}
|
||||
if(img_path[strlen(img_path)-1]!='/')
|
||||
if(img_path[0] || img_path[strlen(img_path)-1]!='/')
|
||||
strcat(img_path,"/");
|
||||
img_name= img_path+strlen(img_path);
|
||||
|
||||
@ -659,9 +663,15 @@ int Xorriso_add_tree(struct XorrisO *xorriso, struct iso_tree_node_dir *dir,
|
||||
/* handle overwrite situation */;
|
||||
if(xorriso->do_overwrite==1 ||
|
||||
(xorriso->do_overwrite==2 && !target_is_dir)) {
|
||||
ret= Xorriso_rmi(xorriso, img_path, 1);
|
||||
ret= Xorriso_rmi(xorriso, NULL, img_path, 1|8);
|
||||
if(ret<=0)
|
||||
goto was_problem;
|
||||
if(ret==3) {
|
||||
sprintf(xorriso->info_text, "User revoked adding of: %s",
|
||||
Text_shellsafe(disk_path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
||||
goto was_problem;
|
||||
}
|
||||
node= NULL;
|
||||
} else {
|
||||
sprintf(xorriso->info_text,
|
||||
@ -715,7 +725,7 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
|
||||
int flag)
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
char path[SfileadrL], *apt, *npt, *cpt;
|
||||
char path[SfileadrL], *apt, *npt, *cpt, sfe[4*SfileadrL];
|
||||
struct iso_tree_node_dir *dir;
|
||||
struct iso_tree_node *node;
|
||||
int done= 0, is_dir= 0, l, ret, target_is_dir, source_is_dir;
|
||||
@ -810,9 +820,15 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
|
||||
/* handle overwrite situation */;
|
||||
if(xorriso->do_overwrite==1 ||
|
||||
(xorriso->do_overwrite==2 && !target_is_dir)) {
|
||||
ret= Xorriso_rmi(xorriso, path, 1);
|
||||
ret= Xorriso_rmi(xorriso, NULL, path, 1|8);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
if(ret==3) {
|
||||
sprintf(xorriso->info_text, "User revoked adding of: %s",
|
||||
Text_shellsafe(disk_path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
||||
return(0);
|
||||
}
|
||||
node= NULL;
|
||||
goto handle_path_node;
|
||||
}
|
||||
@ -1366,50 +1382,103 @@ int Xorriso_node_from_path(struct XorrisO *xorriso, struct iso_volume *volume,
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= remove whole sub tree: rm -r
|
||||
/* @param boss_iter If not NULL then this is an iterator suitable for
|
||||
iso_tree_node_remove_iter() which is then to be used instead
|
||||
of iso_tree_node_remove().
|
||||
@param flag bit0= remove whole sub tree: rm -r
|
||||
bit1= remove empty directory: rmdir
|
||||
bit2= recursion: do not reassure in mode 2 "tree"
|
||||
bit3= this is for overwriting and not for plain removal
|
||||
@return <=0 = error
|
||||
1 = removed simple node
|
||||
2 = removed directory or tree
|
||||
3 = did not remove on user revocation
|
||||
*/
|
||||
int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
|
||||
int Xorriso_rmi(struct XorrisO *xorriso, void *boss_iter,
|
||||
char *path, int flag)
|
||||
{
|
||||
int ret, is_dir= 0;
|
||||
struct iso_tree_node *victim_node;
|
||||
struct iso_tree_node_dir *boss_node;
|
||||
int ret, is_dir= 0, pl, not_removed= 0;
|
||||
struct iso_tree_node *victim_node, *node;
|
||||
struct iso_tree_node_dir *boss_node, *root_dir;
|
||||
struct iso_tree_iter *iter= NULL;
|
||||
struct iso_volume *volume;
|
||||
char sfe[4*SfileadrL];
|
||||
char sfe[4*SfileadrL], sub_path[2*SfileadrL], *sub_name, *name;
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
goto ex;
|
||||
|
||||
if(Xorriso_much_too_long(xorriso, strlen(path), 0)<=0)
|
||||
return(0);
|
||||
{ret= 0; goto ex;}
|
||||
ret= Xorriso_node_from_path(xorriso, volume, path, &victim_node, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
goto ex;
|
||||
root_dir= iso_volume_get_root(volume);
|
||||
if(((void *) root_dir) == ((void *) victim_node)) {
|
||||
sprintf(xorriso->info_text, "May not delete root directory");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
if(LIBISO_ISDIR(victim_node))
|
||||
is_dir= 1;
|
||||
if(!(flag&1)) { /* not rm -r */
|
||||
if(is_dir) {
|
||||
if(is_dir) {
|
||||
if(flag&1) { /* rm -r */
|
||||
if(xorriso->do_reassure==1 && !xorriso->request_not_to_ask) {
|
||||
/* Iterate over subordinates and delete them */
|
||||
/* this might become standard if access permissions get respected */
|
||||
|
||||
iter= iso_tree_node_children((struct iso_tree_node_dir *) victim_node);
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
pl= strlen(path);
|
||||
strcpy(sub_path, path);
|
||||
if(pl==0 || sub_path[pl-1]!='/') {
|
||||
sub_path[pl++]= '/';
|
||||
sub_path[pl]= 0;
|
||||
}
|
||||
sub_name= sub_path+pl;
|
||||
while((node= iso_tree_iter_next(iter)) != NULL
|
||||
&& !xorriso->request_to_abort) {
|
||||
name= (char *) iso_tree_node_get_name(node);
|
||||
if(Xorriso_much_too_long(xorriso, pl+1+strlen(name), 0)<=0)
|
||||
{ret= 0; goto ex;}
|
||||
strcpy(sub_name, name);
|
||||
ret= Xorriso_rmi(xorriso, iter, sub_path, (flag&(1|2|8))|4);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(ret==3)
|
||||
not_removed= 1;
|
||||
}
|
||||
if(not_removed) {
|
||||
if(!(flag&4)) {
|
||||
sprintf(xorriso->info_text, "Directory not removed: %s",
|
||||
Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
||||
}
|
||||
ret= 3; goto ex;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(!(flag&2)) { /* not rmdir */
|
||||
sprintf(xorriso->info_text, "%s in loaded ISO image is a directory",
|
||||
Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
|
||||
/* >>> check whether directory is empty */;
|
||||
|
||||
sprintf(xorriso->info_text,
|
||||
"Single directory removal not implemented yet");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
iter= iso_tree_node_children((struct iso_tree_node_dir *) victim_node);
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
if(iso_tree_iter_next(iter)!=NULL) {
|
||||
sprintf(xorriso->info_text, "Directory not empty on attempt to delete");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(xorriso->request_to_abort)
|
||||
{ret= 3; goto ex;}
|
||||
|
||||
boss_node= iso_tree_node_get_parent(victim_node);
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
if(boss_node==NULL) {
|
||||
@ -1417,26 +1486,69 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
|
||||
"Cannot find parent node of %s in loaded ISO image",
|
||||
Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
|
||||
if(xorriso->do_reassure) {
|
||||
|
||||
/* >>> ask user */;
|
||||
|
||||
while((xorriso->do_reassure==1 || (xorriso->do_reassure==2 && !(flag&4)))
|
||||
&& !xorriso->request_not_to_ask) {
|
||||
Xorriso_ls_filev(xorriso, 1, &path, (off_t) 0, 1|2); /* ls -l */
|
||||
if(is_dir)
|
||||
Xorriso_ls_filev(xorriso, 1, &path, (off_t) 0, 2|4); /* du -s */
|
||||
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);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(xorriso->request_to_abort) {
|
||||
if(!(flag&4)) {
|
||||
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= iso_tree_node_remove(boss_node, victim_node);
|
||||
if(boss_iter!=NULL) {
|
||||
ret= iso_tree_node_remove_iter((struct iso_tree_iter *) boss_iter);
|
||||
if(ret<0)
|
||||
ret= -1;
|
||||
} else
|
||||
ret= iso_tree_node_remove(boss_node, victim_node);
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
if(ret==-1) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Internal failure to remove %s from loaded ISO image",
|
||||
Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
return(-1);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
xorriso->volset_change_pending= 1;
|
||||
return(1+!!is_dir);
|
||||
ret= 1+!!is_dir;
|
||||
ex:;
|
||||
if(iter!=NULL)
|
||||
iso_tree_iter_free(iter);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
@ -1620,6 +1732,7 @@ ex:;
|
||||
|
||||
|
||||
/* @param flag bit0= long format
|
||||
bit1= do not print count of nodes
|
||||
bit2= du format
|
||||
*/
|
||||
int Xorriso_ls_filev(struct XorrisO *xorriso, int filec, char **filev,
|
||||
@ -1671,7 +1784,7 @@ much_too_long:;
|
||||
}
|
||||
}
|
||||
|
||||
if(!(flag&4)) {
|
||||
if(!(flag&(2|4))) {
|
||||
sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec-was_error);
|
||||
Xorriso_info(xorriso,0);
|
||||
if(filec-was_error<=0)
|
||||
@ -1958,9 +2071,15 @@ int Xorriso_rename(struct XorrisO *xorriso, char *origin, char *dest, int flag)
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
} else if(dest_ret>0) {
|
||||
ret= Xorriso_rmi(xorriso, eff_dest, 0);
|
||||
ret= Xorriso_rmi(xorriso, NULL, eff_dest, 8);
|
||||
if(ret<=0)
|
||||
return(0);
|
||||
if(ret==3) {
|
||||
sprintf(xorriso->info_text, "User revoked renaming of: %s",
|
||||
Text_shellsafe(eff_origin, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure existence of destination directory */
|
||||
|
Reference in New Issue
Block a user