Implemented -find option -exec echo, chown, chgrp, chmod, alter_date, lsdl
This commit is contained in:
@ -2818,31 +2818,80 @@ int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t,
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
char *abs_path, char *show_path,
|
||||
struct iso_tree_node *node, int flag)
|
||||
{
|
||||
int ret, type, action= 0;
|
||||
uid_t user= 0;
|
||||
gid_t group= 0;
|
||||
time_t date= 0;
|
||||
mode_t mode_or= 0, mode_and= ~1;
|
||||
char *target, sfe[5*SfileadrL];
|
||||
|
||||
action= Findjob_get_action_parms(job, &target, &user, &group,
|
||||
&mode_and, &mode_or, &type, &date, 0);
|
||||
if(action<0)
|
||||
action= 0;
|
||||
|
||||
if(action==1) {
|
||||
/* >>> rm */;
|
||||
} else if(action==2) {
|
||||
|
||||
/* >>> rm_r */;
|
||||
|
||||
} else if(action==3) {
|
||||
|
||||
/* >>> mv target */;
|
||||
|
||||
} else if(action==4) { /* chown */
|
||||
ret= Xorriso_set_uid(xorriso, abs_path, user, 0);
|
||||
} else if(action==5) { /* chgrp */
|
||||
ret= Xorriso_set_gid(xorriso, abs_path, group, 0);
|
||||
} else if(action==6) { /* chmod */
|
||||
ret= Xorriso_set_st_mode(xorriso, abs_path, mode_and, mode_or, 0);
|
||||
} else if(action==7) { /* alter_date */
|
||||
ret= Xorriso_set_time(xorriso, abs_path, date, type&7);
|
||||
} else if(action==8) { /* lsdl */
|
||||
ret= Xorriso_ls_filev(xorriso, "", 1, &abs_path, (off_t) 0, 1|2|8);
|
||||
} else {
|
||||
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
ret= 0;
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
void *dir_node_generic, char *dir_path,
|
||||
struct stat *dir_stbuf, int depth, int flag)
|
||||
{
|
||||
int ret;
|
||||
int ret, action= 0;
|
||||
struct iso_tree_iter *iter= NULL;
|
||||
struct iso_tree_node_dir *dir_node;
|
||||
struct iso_tree_node *node;
|
||||
struct iso_volume *volume;
|
||||
struct stat stbuf;
|
||||
char *name;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char path[SfileadrL], sfe[5*SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
char *path= NULL, *sfe= NULL;
|
||||
char *path= NULL, *sfe= NULL, *abs_path= NULL;
|
||||
|
||||
sfe= malloc(5*SfileadrL);
|
||||
path= malloc(SfileadrL);
|
||||
if(sfe==NULL || path==NULL) {
|
||||
abs_path= malloc(SfileadrL);
|
||||
if(sfe==NULL || path==NULL || abs_path==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
action= Findjob_get_action(job, 0);
|
||||
if(action<0)
|
||||
action= 0;
|
||||
|
||||
dir_node= (struct iso_tree_node_dir *) dir_node_generic;
|
||||
if(dir_node==NULL) {
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
@ -2868,9 +2917,18 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
ret= Findjob_test(job, name, NULL, dir_stbuf, depth, 0);
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
if(ret>0) {
|
||||
if(ret>0 && action==0) {
|
||||
|
||||
#ifdef NIX
|
||||
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(dir_path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
#else
|
||||
ret= Xorriso_findi_action(xorriso, job, path, dir_path,
|
||||
(struct iso_tree_node *) dir_node, 0);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
#endif /* ! NIX */
|
||||
|
||||
}
|
||||
}
|
||||
if(!LIBISO_ISDIR((struct iso_tree_node *) dir_node))
|
||||
@ -2898,8 +2956,21 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
if(ret<0)
|
||||
goto ex;
|
||||
if(ret>0) {
|
||||
|
||||
#ifdef NIX
|
||||
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_result(xorriso, 0);
|
||||
#else
|
||||
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, path, abs_path, 1|4);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
ret= Xorriso_findi_action(xorriso, job, abs_path, path, node, 0);
|
||||
if(ret<=0) {
|
||||
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
|
||||
goto ex;
|
||||
}
|
||||
#endif /* ! NIX */
|
||||
|
||||
}
|
||||
|
||||
if(S_ISDIR(stbuf.st_mode)) {
|
||||
@ -2918,6 +2989,8 @@ ex:;
|
||||
free(sfe);
|
||||
if(path!=NULL)
|
||||
free(path);
|
||||
if(abs_path!=NULL)
|
||||
free(abs_path);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
|
Reference in New Issue
Block a user