From 124759d74cf797c96962bf0aebb2aa792df2d83a Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Thu, 6 Mar 2008 11:43:08 +0000 Subject: [PATCH] New -find actions "rm" and "rm_r", silenced comparison results with -update* --- libisoburn/trunk/xorriso/xorriso.1 | 30 ++++++--- libisoburn/trunk/xorriso/xorriso.c | 50 ++++++++------ libisoburn/trunk/xorriso/xorriso_timestamp.h | 2 +- libisoburn/trunk/xorriso/xorrisoburn.c | 68 +++++++++----------- libisoburn/trunk/xorriso/xorrisoburn.h | 3 + 5 files changed, 88 insertions(+), 65 deletions(-) diff --git a/libisoburn/trunk/xorriso/xorriso.1 b/libisoburn/trunk/xorriso/xorriso.1 index ec4c9353..49ec2a4d 100644 --- a/libisoburn/trunk/xorriso/xorriso.1 +++ b/libisoburn/trunk/xorriso/xorriso.1 @@ -696,35 +696,35 @@ may have specific parameters. See also their particular descriptions. .br "chown" and "chown_r" change the ownership and get the user id as param. E.g.: .br - -find / -exec chown thomas + -find / -exec chown thomas -- .br "chgrp" and "chgrp_r" change the group attribute and get the group id as param. E.g.: .br - -find / name 'news*' -type d -exec chgrp_r staff + -find / name 'news*' -type d -exec chgrp_r staff -- .br "chmod" and "chmod_r" change access permissions and get a mode string as param. E.g.: .br - -find / -exec chmod a-w,a+r + -find / -exec chmod a-w,a+r -- .br "alter_date" and "alter_date_r" change the timestamps. They get a type character and a timestring as params. E.g.: .br - -find / -exec alter_date "m" "Dec 30 19:34:12 2007" + -find / -exec alter_date "m" "Dec 30 19:34:12 2007" -- .br "lsdl" prints file information like shell command ls -dl. E.g.: .br - -find / -exec lsdl + -find / -exec lsdl -- .br "compare" performs command -compare with the found file address as iso_rr_path and the corresponding file address below its argument disk_path_start. For this the iso_rr_path of the -find command gets replaced by the disk_path_start. E.g.: .br - -find / -exec compare /home/thomas + -find / -exec compare /home/thomas -- .br "update" performs command -update with the found file address as iso_rr_path. The corresponding file address is determined like with above "compare". @@ -733,13 +733,27 @@ WARNING: This action is fewly tested and has potential to spoil your ISO image. .br E.g.: .br - -find / -exec update /home/thomas + -find / -exec update /home/thomas -- +.br +"rm" removes the found iso_rr_path from the image if it is not a directory with +files in it. I.e. this "rm" includes "rmdir". +.br +E.g.: +.br + -find / -name *.doc -exec rm -- +.br +"rm_r" removes the found iso_rr_path from the image, including whole directory +trees. +.br +E.g.: +.br + -find /uh/oh -name *private* -exec rm_r -- .br "find" performs another run of -find on the matching file address. It accepts the same params as -find, except iso_rr_path. E.g.: .br - -find / -name '???' -type d -exec find -name '[abc]*' -exec chmod a-w,a+r + -find / -name '???' -type d -exec find -name '[abc]*' -exec chmod a-w,a+r -- .br If not used as last command in the line then the argument list needs to get terminated by "--". diff --git a/libisoburn/trunk/xorriso/xorriso.c b/libisoburn/trunk/xorriso/xorriso.c index ae4732a4..37f6cade 100644 --- a/libisoburn/trunk/xorriso/xorriso.c +++ b/libisoburn/trunk/xorriso/xorriso.c @@ -2372,14 +2372,22 @@ struct FindjoB { regmatch_t name_match; #endif - /* b = blockdev, c = chardev, d = directory, p = fifo, f = reg , - = reg, - s = socket, X = other , 0x0 = test inactive + /* b = blockdev + c = chardev + d = directory + p = fifo + f = reg + - = reg + s = socket +>>> m = subordinate mountpoint (does never match find start directory) + X = other + 0x0 = test inactive */ char file_type; /* 0= echo ->>> 1= rm +>>> 1= rm (also rmdir) >>> 2= rm_r >>> 3= mv target 4= chown user @@ -3290,6 +3298,7 @@ int Xorriso_pacifier_reset(struct XorrisO *xorriso, int flag) @param current_object A string telling the object currently processed. Ignored if "". @param flag bit0= report unconditionally, no time check + bit1= report count <=0 (no thank you for being patient then) */ int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done, off_t count, off_t todo, char *current_object, @@ -3305,7 +3314,7 @@ int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done, since= current_time - xorriso->start_time; if((flag&1)&&since<1.0) since= 1.0; - if(count<=0.0) { + if(count<=0.0 && !(flag&2)) { sprintf(xorriso->info_text, "Thank you for being patient since %.f seconds", since); } else if(todo<=0.0) { @@ -4510,7 +4519,7 @@ int Xorriso_find_compare(struct XorrisO *xorriso, void *boss_iter, follow_links= (xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&2))) <<28; ret= Xorriso_compare_2_files(xorriso, disk_path, iso_path, adrc, &result, - 2|follow_links|(1<<29)); + 2|follow_links|(1<<29)|((flag&1)<<31)); if(retfind_compare_result) xorriso->find_compare_result= ret; if(flag&1) { @@ -6147,7 +6156,7 @@ int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job, ret= 1; } else if(action==18) { /* add_missing */ ret= Xorriso_compare_2_files(xorriso, abs_path, iso_path, abs_path+dpl, - &compare_result, 4); + &compare_result, 4|(1<<31)); if(retfind_compare_result) xorriso->find_compare_result= ret; if(ret==0) { @@ -6226,17 +6235,12 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job, if(ret<0) goto ex; if(ret>0) { -#ifdef NIX - sprintf(xorriso->result_line, "%s\n", Text_shellsafe(dir_path, sfe, 0)); - Xorriso_result(xorriso, 0); -#else ret= Xorriso_findx_action(xorriso, job, abs_dir_path, dir_path, depth, flag&1); if(ret<=0) { if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0) goto ex; } -#endif } } if(!S_ISDIR(dir_stbuf->st_mode)) @@ -7137,7 +7141,7 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter, ret= 1; if(ret>0 && xorriso->info_text[0]) { strcat(xorriso->info_text, Text_shellsafe(iso_rr_path, sfe, 0)); - Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 1); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0); } return(ret); } @@ -8374,11 +8378,12 @@ sorry_ex: /* @param flag bit0= -findx rather than -findi bit1= do not reset pacifier, no final pacifier message do not reset find_compare_result + bit2= do not count deleted files with rm and rm_r */ int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv, int *idx, int flag) { - int ret, i, end_idx, type= 0, action; + int ret, i, end_idx, type= 0, action, deleter= 0; struct FindjoB *job, *first_job= NULL, *new_job; char *start_path, sfe[5*SfileadrL], *cpt, other_path_start[SfileadrL]; struct stat dir_stbuf; @@ -8425,13 +8430,15 @@ not_enough_arguments:; cpt++; if(strcmp(cpt, "echo")==0) { Findjob_set_action_target(job, 0, NULL, 0); + } else if(strcmp(cpt, "rm")==0) { + Findjob_set_action_target(job, 1, NULL, 0); + deleter= 1; + } else if(strcmp(cpt, "rm_r")==0) { + Findjob_set_action_target(job, 2, NULL, 0); + deleter= 1; #ifdef NIX /* >>> not implemented yet */; - } else if(strcmp(cpt, "rm")==0) { - Findjob_set_action_target(job, 1, NULL, 0); - } else if(strcmp(cpt, "rm_r")==0) { - Findjob_set_action_target(job, 2, NULL, 0); } else if(strcmp(cpt, "mv")==0) { if(i+1>=end_idx) goto not_enough_arguments; @@ -8570,9 +8577,12 @@ sorry_ex:; 0); else ret= Xorriso_findi(xorriso, first_job, NULL, (off_t) 0, NULL, - start_path, &dir_stbuf, 0, 0); + start_path, &dir_stbuf, 0, (flag&4)>>1); ex:; - if(mem_lut!=xorriso->last_update_time && mem_lut!=0.0 && !(flag&2)) + if(deleter && !(flag&2)) + Xorriso_pacifier_callback(xorriso, "iso_rr_paths deleted", + xorriso->pacifier_count, 0, "", 1|2); + else if(mem_lut!=xorriso->last_update_time && mem_lut!=0.0 && !(flag&2)) Xorriso_pacifier_callback(xorriso, "content bytes read", xorriso->pacifier_count, 0, "", 1); Findjob_destroy(&first_job, 0); @@ -10050,7 +10060,7 @@ int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path, /* compare ctime too, no filename reporting, eventually silent */ follow_links= (xorriso->do_follow_links || xorriso->do_follow_param) <<28; ret= Xorriso_compare_2_files(xorriso, disk_path, ipth, "", &result, - 2 | follow_links | ((flag&4)<<27) | (1<<30)); + 2 | follow_links | ((flag&4)<<27) | (3<<30)); if(ret==0) { uret= Xorriso_update_interpreter(xorriso, NULL, result, disk_path, ipth, 0); diff --git a/libisoburn/trunk/xorriso/xorriso_timestamp.h b/libisoburn/trunk/xorriso/xorriso_timestamp.h index 3fe44ebf..e3d76dfc 100644 --- a/libisoburn/trunk/xorriso/xorriso_timestamp.h +++ b/libisoburn/trunk/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2008.03.05.173329" +#define Xorriso_timestamP "2008.03.06.114233" diff --git a/libisoburn/trunk/xorriso/xorrisoburn.c b/libisoburn/trunk/xorriso/xorrisoburn.c index 8868c853..22f02d4b 100644 --- a/libisoburn/trunk/xorriso/xorrisoburn.c +++ b/libisoburn/trunk/xorriso/xorrisoburn.c @@ -2478,6 +2478,7 @@ int Xorriso_cannot_create_iter(struct XorrisO *xorriso, int iso_error,int flag) bit1= remove empty directory: rmdir bit2= recursion: do not reassure in mode 2 "tree" bit3= this is for overwriting and not for plain removal + bit4= count deleted files in xorriso->pacifier_count @return <=0 = error 1 = removed simple node 2 = removed directory or tree @@ -2572,7 +2573,7 @@ cannot_create_iter:; if(Xorriso_much_too_long(xorriso, pl+1+strlen(name), 0)<=0) {ret= 0; goto rm_r_problem_handler;} strcpy(sub_name, name); - ret= Xorriso_rmi(xorriso, iter, sub_path, (flag&(1|2|8))|4); + ret= Xorriso_rmi(xorriso, iter, sub_path, (flag&(1|2|8|16))|4); if(ret==3 || ret<=0 || xorriso->request_to_abort) { rm_r_problem_handler:; not_removed= 1; @@ -2691,6 +2692,8 @@ dir_not_removed:; Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0); ret= -1; goto ex; } + if(flag&16) + xorriso->pacifier_count++; xorriso->volset_change_pending= 1; ret= 1+!!is_dir; ex:; @@ -3782,13 +3785,14 @@ int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t, /* @param flag bit0= not a command parameter (directory iteration or recursion) + bit1= do not count deleted files with rm and rm_r */ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job, IsoDirIter *boss_iter, off_t boss_mem, char *abs_path, char *show_path, IsoNode *node, int depth, int flag) { - int ret= 0, type, action= 0; + int ret= 0, type, action= 0, hflag; uid_t user= 0; gid_t group= 0; time_t date= 0; @@ -3802,12 +3806,16 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job, if(action<0) action= 0; - if(action==1) { - /* >>> rm */; - } else if(action==2) { - - /* >>> rm_r */; - + hflag= 16*!(flag&2); + if(action==1) { /* rm (including rmdir) */ + ret= Xorriso_fake_stbuf(xorriso, abs_path, &dir_stbuf, &node, 1); + if(ret>0) { + if(S_ISDIR(dir_stbuf.st_mode)) + hflag= 2; + ret= Xorriso_rmi(xorriso, boss_iter, abs_path, hflag); + } + } else if(action==2) { /* rm_r */ + ret= Xorriso_rmi(xorriso, boss_iter, abs_path, 1|hflag); } else if(action==3) { /* >>> mv target */; @@ -3864,6 +3872,7 @@ int Xorriso__node_lba_cmp(const void *node1, const void *node2) provides the memory of proper type. @param flag bit0= initialize iteration bit1= action needs full freedom of object manipulation + bit2= action needs LBA sorted iteration bit31= end iteration (mandatory !) */ int Xorriso_findi_iter(struct XorrisO *xorriso, IsoDir *dir_node, off_t *mem, @@ -3887,7 +3896,7 @@ cannot_iter:; Xorriso_cannot_create_iter(xorriso, ret, 0); return(-1); } - if(flag&2) { + if((flag&2)|(flag&4)) { /* copy list of nodes and prepare soft iterator */ *node_count= 0; while(iso_dir_iter_next(*iter, &node) == 1) @@ -3928,7 +3937,7 @@ cannot_iter:; *iter= NULL; *node_count= *node_idx; *node_idx= 0; - if(*node_count>1) + if((flag&4) && *node_count>1) qsort(*node_array, *node_count, sizeof(IsoNode *), Xorriso__node_lba_cmp); } @@ -3966,31 +3975,27 @@ cannot_iter:; /* @param flag bit0= recursion + bit1= do not count deleted files with rm and rm_r */ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job, void *boss_iter, off_t boss_mem, void *dir_node_generic, char *dir_path, struct stat *dir_stbuf, int depth, int flag) { - int ret, action= 0; + int ret, action= 0, hflag; IsoDirIter *iter= NULL; IsoDir *dir_node= NULL; IsoNode *node, *iso_node; IsoImage *volume; struct stat stbuf; char *name; + off_t mem; + IsoNode **node_array= NULL; + int node_count, node_idx; #ifdef Xorriso_fat_local_meM char path[SfileadrL], abs_path[SfileadrL]; #else /* Xorriso_fat_local_meM */ char *path= NULL, *abs_path= NULL; - off_t mem; - -#define Xorriso_findi_new_iteR yes - -#ifdef Xorriso_findi_new_iteR - IsoNode **node_array= NULL; - int node_count, node_idx; -#endif path= malloc(SfileadrL); abs_path= malloc(SfileadrL); @@ -4033,7 +4038,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job, ret= Xorriso_findi_action(xorriso, job, (IsoDirIter *) boss_iter, boss_mem, path, dir_path, (IsoNode *) dir_node, depth, - flag&1); + flag&(1|2)); if(ret<=0) goto ex; } @@ -4041,12 +4046,15 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job, if(!LIBISO_ISDIR((IsoNode *) dir_node)) {ret= 2; goto ex;} -#ifdef Xorriso_findi_new_iteR - mem= boss_mem; + hflag= 1; + if(action==1 || action==2 || action==3 || action==14) + hflag|= 2; /* need freedom to manipulate image */ + if(action==14 || action==17) + hflag|= 4; /* need LBA sorted iteration for good data reading performance */ ret= Xorriso_findi_iter(xorriso, dir_node, &mem, &iter, &node_array, &node_count, &node_idx, - &node, 1|((action==14 || action==17)<<1)); + &node, hflag); if(ret<=0) goto ex; while(1) { @@ -4056,18 +4064,6 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job, goto ex; if(ret==0 || xorriso->request_to_abort) break; - -#else - - ret= iso_dir_get_children(dir_node, &iter); - if(ret<0) { - Xorriso_cannot_create_iter(xorriso, ret, 0); - {ret= -1; goto ex;} - } - while(iso_dir_iter_next(iter, &node) == 1 && !xorriso->request_to_abort) { - -#endif /* ! Xorriso_findi_new_iteR */ - name= (char *) iso_node_get_name(node); ret= Xorriso_make_abs_adr(xorriso, dir_path, name, path, 4); if(ret<=0) @@ -4086,7 +4082,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job, if(ret<=0) goto ex; ret= Xorriso_findi_action(xorriso, job, iter, mem, - abs_path, path, node, depth, 1); + abs_path, path, node, depth, 1|(flag&2)); if(ret<=0) { if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0) goto ex; diff --git a/libisoburn/trunk/xorriso/xorrisoburn.h b/libisoburn/trunk/xorriso/xorrisoburn.h index e56bd5c4..7f259291 100644 --- a/libisoburn/trunk/xorriso/xorrisoburn.h +++ b/libisoburn/trunk/xorriso/xorrisoburn.h @@ -139,6 +139,9 @@ int Xorriso_set_gid(struct XorrisO *xorriso, char *in_path, gid_t gid, int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t, int flag); +/* @param flag bit0= recursion + bit1= do not count deleted files with rm and rm_r +*/ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job, void *boss_iter, off_t boss_mem, void *dir_node_generic, char *dir_path,