From 2b181fcb844b8df417ceafde96bc37e3f6e26479 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sun, 21 Oct 2007 09:48:17 +0000 Subject: [PATCH] Implemented -rm and -rm_r --- test/xorriso.1 | 6 +- test/xorriso.c | 30 ++++++--- test/xorriso_private.h | 3 + test/xorriso_timestamp.h | 2 +- test/xorrisoburn.c | 128 ++++++++++++++++++++++++++++++++++----- test/xorrisoburn.h | 10 +++ 6 files changed, 152 insertions(+), 27 deletions(-) diff --git a/test/xorriso.1 b/test/xorriso.1 index 8daab226..408f4b65 100644 --- a/test/xorriso.1 +++ b/test/xorriso.1 @@ -2,7 +2,7 @@ .\" First parameter, NAME, should be all caps .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" 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. .\" .\" Some roff macros, for reference: @@ -273,10 +273,10 @@ into the ISO image. Use the same rules for generating the ISO addresses as would be done with shell command cp -r. .TP -> \fB\-rm\fR iso_rr_path [...] +\fB\-rm\fR iso_rr_path [...] Delete the given files from the ISO image. .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. .TP > \fB\-mv\fR iso_rr_path [...] iso_rr_path diff --git a/test/xorriso.c b/test/xorriso.c index 67f6142e..cf2e4928 100644 --- a/test/xorriso.c +++ b/test/xorriso.c @@ -3129,6 +3129,9 @@ int Xorriso_option_add(struct XorrisO *xorriso, int argc, char **argv, ret= Xorriso_graft_in(xorriso, source, target, 0); if(ret<=0) 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; 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 *idx, int flag) { - int i, end_idx; + int i, end_idx, ret; + char path[SfileadrL]; end_idx= Xorriso__end_idx(argc, argv, *idx, 0); - fprintf(stderr, ">>> LIBISOFS : -rm%si ", ((flag&1) ? "_r" : "")); - for(i= *idx; iwdi, 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; - return(1); + return(ret); } diff --git a/test/xorriso_private.h b/test/xorriso_private.h index a886422b..4ad6f99e 100644 --- a/test/xorriso_private.h +++ b/test/xorriso_private.h @@ -187,5 +187,8 @@ int Sfile_str(char target[SfileadrL], char *source, int flag); double Sfile_microtime(int flag); +char *Text_shellsafe(char *in_text, char *out_text, int flag); + + #endif /* Xorriso_private_includeD */ diff --git a/test/xorriso_timestamp.h b/test/xorriso_timestamp.h index 9d49af31..5327f78c 100644 --- a/test/xorriso_timestamp.h +++ b/test/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2007.10.20.194918" +#define Xorriso_timestamP "2007.10.21.094818" diff --git a/test/xorrisoburn.c b/test/xorrisoburn.c index ff2e563a..869b7af4 100644 --- a/test/xorrisoburn.c +++ b/test/xorrisoburn.c @@ -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); +} + + + diff --git a/test/xorrisoburn.h b/test/xorrisoburn.h index 441eca6d..1d80d2c7 100644 --- a/test/xorrisoburn.h +++ b/test/xorrisoburn.h @@ -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 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 flag); @@ -44,6 +46,14 @@ int Xorriso_blank_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 */