This commit is contained in:
Thomas Schmitt 2008-02-28 21:22:50 +00:00
parent 71ee27df4a
commit 40b15ba075
4 changed files with 169 additions and 24 deletions

View File

@ -2827,6 +2827,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->pacifier_fifo= NULL;
m->start_time= 0.0;
m->last_update_time= 0.0;
m->find_compare_result= 1;
m->result_line[0]= 0;
m->result_line_counter= 0;
m->result_page_counter= 0;
@ -4197,6 +4198,8 @@ much_too_long:;
/* @param flag bit0= compare atime
bit1= compare ctime
bit2= check only existence of both file objects
count one or both missing as "difference"
bit29= do not issue pacifier messages
bit30= omit adr_common_tail in report messages
bit31= do not issue result messages
@ -4206,7 +4209,7 @@ int Xorriso_compare_2_files(struct XorrisO *xorriso, char *disk_adr,
char *iso_adr, char *adr_common_tail, int flag)
{
struct stat s1, s2;
int ret, differs= 0, r1, r2, fd1= -1, i, done, wanted;
int ret, differs= 0, r1, r2, fd1= -1, i, done, wanted, missing= 0;
void *stream2= NULL;
char *respt;
char buf1[32*1024], buf2[32*1024], a[5*SfileadrL], sfe[5*SfileadrL];
@ -4216,11 +4219,13 @@ int Xorriso_compare_2_files(struct XorrisO *xorriso, char *disk_adr,
respt= xorriso->result_line;
ret= lstat(disk_adr, &s1);
if(ret==-1) {
sprintf(respt , "? %s : cannot lstat() : %s\n",
sprintf(respt , "? %s (DISK) : cannot lstat() : %s\n",
Text_shellsafe(disk_adr, sfe, 0), strerror(errno));
if(!(flag&(1<<31)))
Xorriso_result(xorriso,0);
return(0);
missing= 1;
if(!(flag&4))
return(0);
}
strcpy(a, Ftypetxt(s1.st_mode, 1));
strcat(a, " ");
@ -4238,9 +4243,14 @@ int Xorriso_compare_2_files(struct XorrisO *xorriso, char *disk_adr,
Text_shellsafe(iso_adr, sfe, 0));
if(!(flag&(1<<31)))
Xorriso_result(xorriso,0);
return(0);
missing= 1;
if(!(flag&4))
return(0);
}
if(flag&4)
return(!missing);
/* Attributes */
if(s1.st_mode != s2.st_mode) {
if((s1.st_mode&~S_IFMT)!=(s2.st_mode&~S_IFMT)) {
@ -4346,11 +4356,12 @@ int Xorriso_compare_2_files(struct XorrisO *xorriso, char *disk_adr,
wanted= sizeof(buf2);
/*
/* ts A80228
I thought to have seen a libisofs bug here but it seems that it was an illusion
*/
#define Libisofs_data_read_as_posiX yes
#ifndef Libisofs_data_read_as_posiX
/* This functions guarantees to deliver full buffers but fails on
/* Workaround for the case that iso_stream_read() fails on
oversized read requests. */
if(r2count+wanted>s2.st_size)
wanted= s2.st_size-r2count;
@ -4442,8 +4453,11 @@ int Xorriso_find_compare(struct XorrisO *xorriso, char *iso_path,
if(strlen(disk_prefix)+strlen(iso_path)-strlen(iso_prefix)>=SfileadrL)
return(-1);
strcpy(adrc, iso_path+strlen(iso_prefix));
sprintf(disk_path, "%s%s%s", disk_prefix, (adrc[0]=='/' ? "" : "/"), adrc);
sprintf(disk_path, "%s%s%s",
disk_prefix, (adrc[0]=='/' || adrc[0]==0 ? "" : "/"), adrc);
ret= Xorriso_compare_2_files(xorriso, disk_path, iso_path, adrc, 2|(1<<29));
if(ret<xorriso->find_compare_result)
xorriso->find_compare_result= ret;
return(ret);
}
@ -6019,6 +6033,57 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd,
}
int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job,
char *abs_path, char *show_path, int depth, int flag)
{
int ret= 0, type, action= 0, dpl;
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], *disk_prefix, iso_path[SfileadrL];
struct FindjoB *subjob;
struct stat stbuf;
action= Findjob_get_action_parms(job, &target, &user, &group,
&mode_and, &mode_or, &type, &date, &subjob, 0);
if(action<0)
action= 0;
if(action<0)
action= 0;
if(action==15 || action==16) { /* in_iso , not_in_iso */
Findjob_get_start_path(job, &disk_prefix, 0);
if(strncmp(abs_path, disk_prefix, strlen(disk_prefix))!=0)
return(-1);
dpl= strlen(disk_prefix);
if(strlen(target)+strlen(abs_path)-dpl >= SfileadrL)
return(-1);
sprintf(iso_path, "%s%s%s",
target, (abs_path[dpl] =='/' || abs_path[dpl]==0 ? "" : "/"),
abs_path+dpl);
}
if(action==15) {
ret= Xorriso_iso_lstat(xorriso, iso_path, &stbuf, 0);
if(ret==-1)
return(1);
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
ret= 1;
} else if(action==16) {
ret= Xorriso_compare_2_files(xorriso, abs_path, iso_path, abs_path+dpl, 4);
if(ret<xorriso->find_compare_result)
xorriso->find_compare_result= ret;
if(ret>=0)
ret= 1;
} else {
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
ret= 1;
}
return(ret);
}
/* @param flag bit0=recursion
*/
int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
@ -6078,8 +6143,16 @@ 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, 0);
if(ret<=0) {
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
goto ex;
}
#endif
}
}
if(!S_ISDIR(dir_stbuf->st_mode))
@ -6127,8 +6200,18 @@ 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(path, sfe, 0));
Xorriso_result(xorriso, 0);
#else
ret= Xorriso_findx_action(xorriso, job, abs_path, path, depth, 0);
if(ret<=0) {
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
goto ex;
}
#endif
}
if(!S_ISDIR(stbuf.st_mode))
no_dive= 1;
@ -7656,13 +7739,14 @@ int Xorriso_option_commit_eject(struct XorrisO *xorriso, char *which, int flag)
@param flag bit0= issue summary message
bit1= do not reset pacifier, no final pacifier message
bit2= do not issue pacifier messages at all
bit3= recursive: -compare_r
*/
int Xorriso_option_compare(struct XorrisO *xorriso, char *disk_path,
char *iso_path, int flag)
{
int ret, mem_pci;
int ret, mem_pci, zero= 0;
double mem_lut;
char *ipth;
char *ipth, *argv[4];
ipth= iso_path;
if(ipth[0]==0)
@ -7674,15 +7758,40 @@ int Xorriso_option_compare(struct XorrisO *xorriso, char *disk_path,
}
mem_pci= xorriso->pacifier_interval;
xorriso->pacifier_interval= 5.0;
ret= Xorriso_compare_2_files(xorriso, disk_path, ipth, "",
2| (1<<30) | ((flag&4)<<27));
if(flag&8) {
xorriso->find_compare_result= 1;
argv[0]= ipth;
argv[1]= "-exec";
argv[2]= "compare";
argv[3]= disk_path;
zero= 0;
ret= Xorriso_option_find(xorriso, 4, argv, &zero, 2); /* -findi */
if(ret>0) {
argv[0]= disk_path;
argv[1]= "-exec";
argv[2]= "not_in_iso";
argv[3]= ipth;
zero= 0;
ret= Xorriso_option_find(xorriso, 4, argv, &zero, 1|2); /* -findx */
if(ret>0)
ret= xorriso->find_compare_result;
else
ret= -1;
} else
ret= -1;
} else {
ret= Xorriso_compare_2_files(xorriso, disk_path, ipth, "",
2| (1<<30) | ((flag&4)<<27));
}
xorriso->pacifier_interval= mem_pci;
if(mem_lut!=xorriso->last_update_time && !(flag&2))
Xorriso_pacifier_callback(xorriso, "content bytes read",
xorriso->pacifier_count, 0, "", 1);
if(ret>0) {
sprintf(xorriso->result_line,
"Ok. Both files match as far as expectable.\n");
"Ok. Both file objects match as far as expectable.\n");
} else if(ret==0) {
sprintf(xorriso->result_line, "Not ok. Differences detected.\n");
} else {
@ -8117,13 +8226,15 @@ sorry_ex:
/* Option -find alias -findi, and -findx */
/* @param flag bit0= -findx rather than -findi
bit1= do not reset pacifier, no final pacifier message
do not reset find_compare_result
*/
int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int ret, i, end_idx, type= 0;
int ret, i, end_idx, type= 0, action;
struct FindjoB *job, *first_job= NULL, *new_job;
char *start_path, sfe[5*SfileadrL], *cpt, disk_path_start[SfileadrL];
char *start_path, sfe[5*SfileadrL], *cpt, other_path_start[SfileadrL];
struct stat dir_stbuf;
uid_t user= 0;
gid_t group= 0;
@ -8141,7 +8252,8 @@ int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
{ret= -1; goto ex;}
}
job= first_job;
if(!(flag&2))
xorriso->find_compare_result= 1;
for(i= *idx+1; i<end_idx; i++) {
if(strcmp(argv[i], "-name")==0) {
if(i+1>=end_idx) {
@ -8247,17 +8359,37 @@ not_enough_arguments:;
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, argv[i],
disk_path_start, 1|2|4);
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdx, argv[i],
other_path_start, 1|2|4|8);
if(ret<=0)
goto ex;
Findjob_set_action_target(job, 14, disk_path_start, 0);
Findjob_set_action_target(job, 14, other_path_start, 0);
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, start_path,sfe, 1|2|4);
if(ret<=0)
goto ex;
Findjob_set_start_path(job, sfe, 0);
Xorriso_pacifier_reset(xorriso, 0);
mem_lut= xorriso->last_update_time;
if(!(flag&2)) {
Xorriso_pacifier_reset(xorriso, 0);
mem_lut= xorriso->last_update_time;
}
} else if(strcmp(cpt, "in_iso")==0 || strcmp(cpt, "not_in_iso")==0) {
if(i+1>=end_idx)
goto not_enough_arguments;
i++;
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, argv[i],
other_path_start, 1|2|4);
if(ret<=0)
goto ex;
if(strcmp(cpt, "in_iso")==0)
action= 15;
else
action= 16;
Findjob_set_action_target(job, action, other_path_start, 0);
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdx, start_path, sfe,
1|2|4|8);
if(ret<=0)
goto ex;
Findjob_set_start_path(job, sfe, 0);
} else {
sprintf(xorriso->info_text, "-find -exec: unknown action %s",
@ -8287,7 +8419,7 @@ sorry_ex:;
else
ret= Xorriso_findi(xorriso, first_job, NULL, start_path, &dir_stbuf, 0, 0);
ex:;
if(mem_lut!=xorriso->last_update_time && mem_lut!=0.0)
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);
@ -9910,6 +10042,10 @@ next_command:;
(*idx)+= 2;
ret= Xorriso_option_compare(xorriso, arg1, arg2, 1);
} else if(strcmp(cmd,"compare_r")==0) {
(*idx)+= 2;
ret= Xorriso_option_compare(xorriso, arg1, arg2, 1|8);
} else if(strcmp(cmd,"cpr")==0 || strcmp(cmd,"cpri")==0) {
ret= Xorriso_option_cpri(xorriso, argc, argv, idx, 0);

View File

@ -218,6 +218,8 @@ struct XorrisO { /* the global context of xorriso */
void *pacifier_fifo;
int find_compare_result; /* 1=everything matches , 0=mismatch , -1=error */
/* result (stdout, R: ) */
char result_line[5*SfileadrL];
int result_line_counter;
@ -330,6 +332,9 @@ int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done,
off_t count, off_t todo, char *current_object,
int flag);
int Xorriso_find_compare(struct XorrisO *xorriso, char *iso_path,
char *iso_prefix, char *disk_prefix, int flag);
int Sfile_str(char target[SfileadrL], char *source, int flag);
double Sfile_microtime(int flag);
@ -403,6 +408,8 @@ int Findjob_set_action_ad(struct FindjoB *o, int type, time_t date, int flag);
int Findjob_set_start_path(struct FindjoB *o, char *start_path, int flag);
int Findjob_get_start_path(struct FindjoB *o, char **start_path, int flag);
#endif /* Xorriso_private_includeD */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.02.28.132656"
#define Xorriso_timestamP "2008.02.28.212210"

View File

@ -3756,7 +3756,9 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
ret= Xorriso_find_compare(xorriso, abs_path, iso_prefix, target, 0);
if(ret>=0)
ret= 1;
} else {
} else if(action==16) { /* not_in_iso */
;
} else { /* includes : 15 in_iso */
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
ret= 1;
@ -3848,7 +3850,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
if(ret<0)
goto ex;
if(ret>0) {
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, path, abs_path, 1|4);
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, path, abs_path, 1|2|4);
if(ret<=0)
goto ex;
ret= Xorriso_findi_action(xorriso, job, abs_path, path, node, depth, 0);