Made -compare* and -update* obey -follow links (-follow mount still not correct)

This commit is contained in:
Thomas Schmitt 2008-03-05 17:34:06 +00:00
parent b9ace51640
commit 84b1543295
3 changed files with 75 additions and 40 deletions

View File

@ -4177,6 +4177,7 @@ int Xorriso_make_abs_adr(struct XorrisO *xorriso, char *wd, char *name,
if(strlen(wd)+1>=SfileadrL) if(strlen(wd)+1>=SfileadrL)
goto much_too_long; goto much_too_long;
strcpy(adr, wd); strcpy(adr, wd);
if(name[0])
if(Sfile_add_to_path(adr, name, 0)<=0) { if(Sfile_add_to_path(adr, name, 0)<=0) {
much_too_long:; much_too_long:;
Xorriso_much_too_long(xorriso, (int) (strlen(adr)+strlen(name)+1), 2); Xorriso_much_too_long(xorriso, (int) (strlen(adr)+strlen(name)+1), 2);
@ -4484,12 +4485,13 @@ I thought to have seen a libisofs bug here but it seems that it was an illusion
/* @param boss_iter Opaque handle to be forwarded to actions in ISO image /* @param boss_iter Opaque handle to be forwarded to actions in ISO image
Set to NULL if calling this function from outside ISO world Set to NULL if calling this function from outside ISO world
@param flag bit0= update rather than compare @param flag bit0= update rather than compare
bit1= find[ix] is in recursion
*/ */
int Xorriso_find_compare(struct XorrisO *xorriso, void *boss_iter, int Xorriso_find_compare(struct XorrisO *xorriso, void *boss_iter,
char *iso_path, char *iso_prefix, char *disk_prefix, char *iso_path, char *iso_prefix, char *disk_prefix,
int flag) int flag)
{ {
int ret, result, uret; int ret, result, uret, follow_links;
char disk_path[SfileadrL], adrc[SfileadrL]; char disk_path[SfileadrL], adrc[SfileadrL];
if(strncmp(iso_path, iso_prefix, strlen(iso_prefix))!=0) if(strncmp(iso_path, iso_prefix, strlen(iso_prefix))!=0)
@ -4505,14 +4507,16 @@ int Xorriso_find_compare(struct XorrisO *xorriso, void *boss_iter,
if(ret<=0) if(ret<=0)
return(ret); return(ret);
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, ret= Xorriso_compare_2_files(xorriso, disk_path, iso_path, adrc, &result,
2|(1<<29)); 2|follow_links|(1<<29));
if(ret<xorriso->find_compare_result) if(ret<xorriso->find_compare_result)
xorriso->find_compare_result= ret; xorriso->find_compare_result= ret;
if(flag&1) { if(flag&1) {
if(ret==0) { if(ret==0) {
uret= Xorriso_update_interpreter(xorriso, boss_iter, uret= Xorriso_update_interpreter(xorriso, boss_iter, result,
result, disk_path, iso_path, 0); disk_path, iso_path, (flag&2)<<1);
if(uret<=0) if(uret<=0)
ret= 0; ret= 0;
} }
@ -6092,6 +6096,8 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd,
} }
/* @param flag bit0= recursion
*/
int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job, int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job,
char *abs_path, char *show_path, int depth, int flag) char *abs_path, char *show_path, int depth, int flag)
{ {
@ -6146,7 +6152,7 @@ int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job,
xorriso->find_compare_result= ret; xorriso->find_compare_result= ret;
if(ret==0) { if(ret==0) {
uret= Xorriso_update_interpreter(xorriso, NULL, compare_result, uret= Xorriso_update_interpreter(xorriso, NULL, compare_result,
abs_path, iso_path, 0); abs_path, iso_path, (flag&1)<<2);
if(uret<=0) if(uret<=0)
ret= 0; ret= 0;
} }
@ -6224,7 +6230,8 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(dir_path, sfe, 0)); sprintf(xorriso->result_line, "%s\n", Text_shellsafe(dir_path, sfe, 0));
Xorriso_result(xorriso, 0); Xorriso_result(xorriso, 0);
#else #else
ret= Xorriso_findx_action(xorriso, job, abs_dir_path, dir_path, depth, 0); ret= Xorriso_findx_action(xorriso, job, abs_dir_path, dir_path, depth,
flag&1);
if(ret<=0) { if(ret<=0) {
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0) if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
goto ex; goto ex;
@ -6277,18 +6284,11 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
if(ret<0) if(ret<0)
goto ex; goto ex;
if(ret>0) { if(ret>0) {
ret= Xorriso_findx_action(xorriso, job, abs_path, path, depth, flag&1);
#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(ret<=0) {
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0) if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
goto ex; goto ex;
} }
#endif
} }
if(!S_ISDIR(stbuf.st_mode)) if(!S_ISDIR(stbuf.st_mode))
no_dive= 1; no_dive= 1;
@ -7081,6 +7081,7 @@ ex:;
/* @param boss_iter Opaque handle to be forwarded to actions in ISO image /* @param boss_iter Opaque handle to be forwarded to actions in ISO image
Set to NULL if calling this function from outside ISO world Set to NULL if calling this function from outside ISO world
@param flag bit2= -follow: this is not a command parameter
*/ */
int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter, int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
int compare_result, char *disk_path, int compare_result, char *disk_path,
@ -7099,14 +7100,20 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
} }
xorriso->info_text[0]= 0; xorriso->info_text[0]= 0;
#ifdef NIX
if((compare_result&(8|64)) && !(compare_result&(1<<16)) ) { if((compare_result&(8|64)) && !(compare_result&(1<<16)) ) {
/* file type, minor+major with device file */
/* <<< tolerate for now: disk_path being softlink to dir, iso being dir */ /* <<< tolerate for now: disk_path being softlink to dir, iso being dir */
/* <<< to be obsoleted by proper link handling in compare_2_files */ /* <<< to be obsoleted by proper link handling in compare_2_files */
/* file type, minor+major with device file */
#else
if(compare_result&(8|64)) {
/* file type, minor+major with device file */
#endif /* NIX */
ret= Xorriso_rmi(xorriso, boss_iter, iso_rr_path, 1); ret= Xorriso_rmi(xorriso, boss_iter, iso_rr_path, 1); /* rm_r */
if(ret>0) if(ret>0)
ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, iso_rr_path, 2); ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, iso_rr_path,
2|(flag&4));
sprintf(xorriso->info_text, "Deleted and re-added "); sprintf(xorriso->info_text, "Deleted and re-added ");
} else if(compare_result&(1)) { } else if(compare_result&(1)) {
@ -7117,7 +7124,8 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
} else if(compare_result&(2|128|(1<<12)|(1<<14)|(1<<15))) { } else if(compare_result&(2|128|(1<<12)|(1<<14)|(1<<15))) {
/* iso_adr not existing, size, cannot open iso file, early eof of iso file /* iso_adr not existing, size, cannot open iso file, early eof of iso file
content bytes differ */ content bytes differ */
ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, iso_rr_path, 2); ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, iso_rr_path,
2|(flag&4));
sprintf(xorriso->info_text, "Added/overwrote "); sprintf(xorriso->info_text, "Added/overwrote ");
} else if(compare_result&(4|16|32|256|512|1024)) { } else if(compare_result&(4|16|32|256|512|1024)) {
@ -7881,7 +7889,7 @@ int Xorriso_option_commit_eject(struct XorrisO *xorriso, char *which, int flag)
int Xorriso_option_compare(struct XorrisO *xorriso, char *disk_path, int Xorriso_option_compare(struct XorrisO *xorriso, char *disk_path,
char *iso_path, int flag) char *iso_path, int flag)
{ {
int ret, mem_pci, zero= 0, result; int ret, mem_pci, zero= 0, result, follow_links;
double mem_lut= 0.0; double mem_lut= 0.0;
char *ipth, *argv[4]; char *ipth, *argv[4];
@ -7918,8 +7926,9 @@ int Xorriso_option_compare(struct XorrisO *xorriso, char *disk_path,
} else } else
ret= -1; ret= -1;
} else { } else {
follow_links= (xorriso->do_follow_links || xorriso->do_follow_param) << 28;
ret= Xorriso_compare_2_files(xorriso, disk_path, ipth, "", &result, ret= Xorriso_compare_2_files(xorriso, disk_path, ipth, "", &result,
2| (1<<30) | ((flag&4)<<27)); 2 | follow_links | ((flag&4)<<27) | (1<<30));
} }
xorriso->pacifier_interval= mem_pci; xorriso->pacifier_interval= mem_pci;
@ -9991,7 +10000,7 @@ int Xorriso_option_uid(struct XorrisO *xorriso, char *uid, int flag)
int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path, int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path,
char *iso_path, int flag) char *iso_path, int flag)
{ {
int ret, mem_pci, zero= 0, result, uret; int ret, mem_pci, zero= 0, result, uret, follow_links;
double mem_lut= 0.0, start_time; double mem_lut= 0.0, start_time;
char *ipth, *argv[4]; char *ipth, *argv[4];
struct stat stbuf; struct stat stbuf;
@ -10039,8 +10048,9 @@ int Xorriso_option_update(struct XorrisO *xorriso, char *disk_path,
ret= -1; ret= -1;
} else { } else {
/* compare ctime too, no filename reporting, eventually silent */ /* 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, ret= Xorriso_compare_2_files(xorriso, disk_path, ipth, "", &result,
2| (1<<30) | ((flag&4)<<27)); 2 | follow_links | ((flag&4)<<27) | (1<<30));
if(ret==0) { if(ret==0) {
uret= Xorriso_update_interpreter(xorriso, NULL, result, disk_path, ipth, uret= Xorriso_update_interpreter(xorriso, NULL, result, disk_path, ipth,
0); 0);

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.03.05.125118" #define Xorriso_timestamP "2008.03.05.173329"

View File

@ -1780,6 +1780,7 @@ int Xorriso_copy_properties(struct XorrisO *xorriso,
Set to NULL if calling this function from outside ISO world Set to NULL if calling this function from outside ISO world
@param flag bit0= mkdir: graft in as empty directory, not as copy from disk @param flag bit0= mkdir: graft in as empty directory, not as copy from disk
bit1= do not report added files bit1= do not report added files
bit2= -follow: this is not a command parameter
@return <=0 = error , 1 = added simple node , 2 = added directory @return <=0 = error , 1 = added simple node , 2 = added directory
*/ */
int Xorriso_graft_in(struct XorrisO *xorriso, void *boss_iter, int Xorriso_graft_in(struct XorrisO *xorriso, void *boss_iter,
@ -1787,9 +1788,10 @@ int Xorriso_graft_in(struct XorrisO *xorriso, void *boss_iter,
{ {
IsoImage *volume; IsoImage *volume;
char path[SfileadrL], *apt, *npt, *cpt, sfe[5*SfileadrL], sfe2[5*SfileadrL]; char path[SfileadrL], *apt, *npt, *cpt, sfe[5*SfileadrL], sfe2[5*SfileadrL];
char *disk_path_pt, resolved_disk_path[SfileadrL];
IsoDir *dir, *hdir; IsoDir *dir, *hdir;
IsoNode *node; IsoNode *node;
int done= 0, is_dir= 0, l, ret, target_is_dir, source_is_dir; int done= 0, is_dir= 0, l, ret, target_is_dir, source_is_dir, resolve_link= 0;
struct stat stbuf; struct stat stbuf;
for(cpt= img_path; 1; cpt++) { for(cpt= img_path; 1; cpt++) {
@ -1824,10 +1826,21 @@ int Xorriso_graft_in(struct XorrisO *xorriso, void *boss_iter,
apt= npt= path; apt= npt= path;
if(!(flag&1)) { if(!(flag&1)) {
if(xorriso->do_follow_links || xorriso->do_follow_param)
ret= stat(disk_path, &stbuf);
else
ret= lstat(disk_path, &stbuf); ret= lstat(disk_path, &stbuf);
if(ret!=-1) {
if(S_ISDIR(stbuf.st_mode))
is_dir= 1;
else if((stbuf.st_mode&S_IFMT)==S_IFLNK &&
(xorriso->do_follow_links ||
(xorriso->do_follow_param && !(flag&4)))) {
resolve_link= 1;
ret= stat(disk_path, &stbuf);
if(ret!=-1) {
if(S_ISDIR(stbuf.st_mode))
is_dir= 1;
}
}
}
if(ret == -1) { if(ret == -1) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
Xorriso_msgs_submit(xorriso, 0, disk_path, 0, "ERRFILE", 0); Xorriso_msgs_submit(xorriso, 0, disk_path, 0, "ERRFILE", 0);
@ -1962,7 +1975,14 @@ attach_source:;
return(ret); return(ret);
} else { } else {
ret= iso_tree_add_node(volume, dir, disk_path, &node); if(resolve_link) {
ret= Xorriso_resolve_link(xorriso, disk_path, resolved_disk_path, 0);
if(ret<=0)
return(ret);
disk_path_pt= resolved_disk_path;
} else
disk_path_pt= disk_path;
ret= iso_tree_add_node(volume, dir, disk_path_pt, &node);
if(ret<0) { if(ret<0) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
Xorriso_msgs_submit(xorriso, 0, disk_path, 0, "ERRFILE", 0); Xorriso_msgs_submit(xorriso, 0, disk_path, 0, "ERRFILE", 0);
@ -3761,6 +3781,8 @@ int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t,
} }
/* @param flag bit0= not a command parameter (directory iteration or recursion)
*/
int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job, int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
IsoDirIter *boss_iter, off_t boss_mem, IsoDirIter *boss_iter, off_t boss_mem,
char *abs_path, char *show_path, char *abs_path, char *show_path,
@ -3803,11 +3825,11 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
} else if(action>=9 && action<=13) { /* actions which have own findjobs */ } else if(action>=9 && action<=13) { /* actions which have own findjobs */
Findjob_set_start_path(subjob, abs_path, 0); Findjob_set_start_path(subjob, abs_path, 0);
ret= Xorriso_findi(xorriso, subjob, boss_iter, boss_mem, NULL, ret= Xorriso_findi(xorriso, subjob, boss_iter, boss_mem, NULL,
abs_path, &dir_stbuf, depth, 0); abs_path, &dir_stbuf, depth, 1);
} else if(action==14 || action==17) { /* compare , update */ } else if(action==14 || action==17) { /* compare , update */
Findjob_get_start_path(job, &iso_prefix, 0); Findjob_get_start_path(job, &iso_prefix, 0);
ret= Xorriso_find_compare(xorriso, (void *) boss_iter, abs_path, iso_prefix, target, ret= Xorriso_find_compare(xorriso, (void *) boss_iter, abs_path,
(action==17)); iso_prefix, target, (action==17)|((flag&1)<<1));
if(ret>=0) if(ret>=0)
ret= 1; ret= 1;
} else if(action==16 || action==18) { /* not_in_iso , add_missing */ } else if(action==16 || action==18) { /* not_in_iso , add_missing */
@ -3943,6 +3965,8 @@ cannot_iter:;
} }
/* @param flag bit0= recursion
*/
int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job, int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
void *boss_iter, off_t boss_mem, void *boss_iter, off_t boss_mem,
void *dir_node_generic, char *dir_path, void *dir_node_generic, char *dir_path,
@ -4008,7 +4032,8 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
if(ret>0) { if(ret>0) {
ret= Xorriso_findi_action(xorriso, job, ret= Xorriso_findi_action(xorriso, job,
(IsoDirIter *) boss_iter, boss_mem, (IsoDirIter *) boss_iter, boss_mem,
path, dir_path, (IsoNode *) dir_node, depth, 0); path, dir_path, (IsoNode *) dir_node, depth,
flag&1);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
} }
@ -4061,7 +4086,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
if(ret<=0) if(ret<=0)
goto ex; goto ex;
ret= Xorriso_findi_action(xorriso, job, iter, mem, ret= Xorriso_findi_action(xorriso, job, iter, mem,
abs_path, path, node, depth, 0); abs_path, path, node, depth, 1);
if(ret<=0) { if(ret<=0) {
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0) if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
goto ex; goto ex;
@ -4070,7 +4095,7 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
if(S_ISDIR(stbuf.st_mode)) { if(S_ISDIR(stbuf.st_mode)) {
ret= Xorriso_findi(xorriso, job, (void *) iter, mem, ret= Xorriso_findi(xorriso, job, (void *) iter, mem,
(void *) node, path, &stbuf, depth+1, flag); (void *) node, path, &stbuf, depth+1, flag|1);
if(ret<0) if(ret<0)
goto ex; goto ex;
} }