Implemented -rm and -rm_r

This commit is contained in:
Thomas Schmitt 2007-10-21 09:48:17 +00:00
parent 62981e7892
commit 2b181fcb84
6 changed files with 152 additions and 27 deletions

View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps .\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1) .\" other parameters are allowed: see man(7), man(1)
.TH XORRIXO 1 "October 20, 2007" .TH XORRISO 1 "October 21, 2007"
.\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.\" Some roff macros, for reference: .\" Some roff macros, for reference:
@ -273,10 +273,10 @@ into the ISO image.
Use the same rules for generating the ISO addresses as Use the same rules for generating the ISO addresses as
would be done with shell command cp -r. would be done with shell command cp -r.
.TP .TP
> \fB\-rm\fR iso_rr_path [...] \fB\-rm\fR iso_rr_path [...]
Delete the given files from the ISO image. Delete the given files from the ISO image.
.TP .TP
> \fB\-rm_r iso_rr_path [...] \fB\-rm_r\fR iso_rr_path [...]
Delete the given files or directory trees from the ISO image. Delete the given files or directory trees from the ISO image.
.TP .TP
> \fB\-mv\fR iso_rr_path [...] iso_rr_path > \fB\-mv\fR iso_rr_path [...] iso_rr_path

View File

@ -3129,6 +3129,9 @@ int Xorriso_option_add(struct XorrisO *xorriso, int argc, char **argv,
ret= Xorriso_graft_in(xorriso, source, target, 0); ret= Xorriso_graft_in(xorriso, source, target, 0);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
sprintf(xorriso->info_text, "Added to ISO image: %s '%s'='%s'\n",
(ret>1 ? "directory" : "file"), target, source);
Xorriso_info(xorriso, 0);
} }
ret= 1; ret= 1;
ex:; ex:;
@ -4334,17 +4337,30 @@ int Xorriso_option_report_about(struct XorrisO *xorriso, char *severity,
int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv, int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag) int *idx, int flag)
{ {
int i, end_idx; int i, end_idx, ret;
char path[SfileadrL];
end_idx= Xorriso__end_idx(argc, argv, *idx, 0); end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : -rm%si ", ((flag&1) ? "_r" : "")); for(i= *idx; i<end_idx; i++) {
for(i= *idx; i<end_idx; i++) if(Sfile_str(path,argv[i],0)<=0)
fprintf(stderr, "%s ", argv[i]); {ret= -1; goto ex;}
fprintf(stderr, "\n"); if(path[0]!='/') {
ret= Sfile_prepend_path(xorriso->wdi, path, 0);
if(ret<=0)
goto ex;
}
ret= Xorriso_rmi(xorriso, path, flag&1);
if(ret<=0)
goto ex;
sprintf(xorriso->info_text, "Removed from ISO image: %s '%s'\n",
(ret>1 ? "subtree" : "file"), path);
Xorriso_info(xorriso, 0);
}
ret= 1;
ex:;
(*idx)= end_idx; (*idx)= end_idx;
return(1); return(ret);
} }

View File

@ -187,5 +187,8 @@ int Sfile_str(char target[SfileadrL], char *source, int flag);
double Sfile_microtime(int flag); double Sfile_microtime(int flag);
char *Text_shellsafe(char *in_text, char *out_text, int flag);
#endif /* Xorriso_private_includeD */ #endif /* Xorriso_private_includeD */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.20.194918" #define Xorriso_timestamP "2007.10.21.094818"

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 Xorriso_get_volume(struct XorrisO *xorriso, struct iso_volume **volume,
int flag) 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) { if(xorriso->in_volset_handle==NULL) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,"No volset is loaded."); 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); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(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); strncpy(path, img_path, sizeof(path)-1);
path[sizeof(path)-1]= 0; path[sizeof(path)-1]= 0;
apt= npt= path; apt= npt= path;
volume= iso_volset_get_volume(
(struct iso_volset *) xorriso->in_volset_handle, 0);
if(lstat(disk_path, &stbuf) == -1) { if(lstat(disk_path, &stbuf) == -1) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
@ -533,11 +545,8 @@ attach_source:;
*npt= '/'; *npt= '/';
} }
Xorriso_process_msg_queues(xorriso,0); 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; xorriso->volset_change_pending= 1;
return(1); return(1+!!is_dir);
} }
@ -979,3 +988,90 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag)
return(1); 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);
}

View File

@ -28,6 +28,8 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag);
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive, int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
int flag); int flag);
/* @return <=0 = error , 1 = added simple node , 2 = added directory
*/
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path, int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag); int flag);
@ -44,6 +46,14 @@ int Xorriso_blank_media(struct XorrisO *xorriso, int flag);
int Xorriso_format_media(struct XorrisO *xorriso, int flag); int Xorriso_format_media(struct XorrisO *xorriso, int flag);
/* @param flag bit0= remove whole sub tree: rm -r
bit1=remove empty directory: rmdir
@return <=0 = error
1 = removed simple node
2 = removed directory or subtree
*/
int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag);
#endif /* Xorrisoburn_includeD */ #endif /* Xorrisoburn_includeD */