Implemented -rm and -rm_r

This commit is contained in:
2007-10-21 09:48:17 +00:00
parent 3752612a03
commit a140a6e566
6 changed files with 152 additions and 27 deletions

View File

@ -406,17 +406,9 @@ int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
}
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag)
int Xorriso_get_volume(struct XorrisO *xorriso, struct iso_volume **volume,
int flag)
{
struct iso_volume *volume;
struct iso_tree_radd_dir_behavior behav= {NULL, 0, 0};
char path[SfileadrL], *apt, *npt;
struct iso_tree_node_dir *dir;
struct iso_tree_node *node;
int done= 0, is_dir= 0, l;
struct stat stbuf;
if(xorriso->in_volset_handle==NULL) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"No volset is loaded.");
@ -430,11 +422,31 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
*volume= iso_volset_get_volume(
(struct iso_volset *) xorriso->in_volset_handle, 0);
return(*volume != NULL);
}
/* @return <=0 = error , 1 = added simple node , 2 = added directory */
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag)
{
struct iso_volume *volume;
struct iso_tree_radd_dir_behavior behav= {NULL, 0, 0};
char path[SfileadrL], *apt, *npt;
struct iso_tree_node_dir *dir;
struct iso_tree_node *node;
int done= 0, is_dir= 0, l, ret;
struct stat stbuf;
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
strncpy(path, img_path, sizeof(path)-1);
path[sizeof(path)-1]= 0;
apt= npt= path;
volume= iso_volset_get_volume(
(struct iso_volset *) xorriso->in_volset_handle, 0);
if(lstat(disk_path, &stbuf) == -1) {
Xorriso_process_msg_queues(xorriso,0);
@ -533,11 +545,8 @@ attach_source:;
*npt= '/';
}
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text, "Added %s '%s'='%s'\n",
(is_dir ? "directory" : "node"), img_path, disk_path);
Xorriso_info(xorriso, 0);
xorriso->volset_change_pending= 1;
return(1);
return(1+!!is_dir);
}
@ -978,4 +987,91 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag)
Xorriso_info(xorriso,0);
return(1);
}
/* @param flag bit0= remove whole sub tree: rm -r
bit1=remove empty directory: rmdir
*/
int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
{
int ret, is_dir= 0;
struct iso_tree_node *victim_node;
struct iso_tree_node_dir *boss_node;
struct iso_volume *volume;
char sfe[4*SfileadrL];
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
if(strlen(path)>=SfileadrL) {
sprintf(xorriso->info_text,
"Path given for ISO image is much too long (%d)", strlen(path));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
victim_node= iso_tree_volume_path_to_node(volume, path);
Xorriso_process_msg_queues(xorriso,0);
if(victim_node==NULL) {
sprintf(xorriso->info_text, "Cannot find path %s in loaded ISO image",
Text_shellsafe(path, sfe, 0));
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(!(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);
}
/* >>> 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);
}
}
boss_node= iso_tree_node_get_parent(victim_node);
Xorriso_process_msg_queues(xorriso,0);
if(boss_node==NULL) {
sprintf(xorriso->info_text,
"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);
}
#ifdef Not_yeT
char boss_adr[SfiladrL], *spt;
struct *check_node;
int l;
/* >>> derive boss_path as dirname from victim_path ... */
check_node= iso_tree_volume_path_to_node(volume, boss_path);
/* >>> compare boss_node and check_node */
#endif /* Not_yeT */
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);
}
xorriso->volset_change_pending= 1;
return(1+!!is_dir);
}