Fixed several bugs with restorie operations

This commit is contained in:
Thomas Schmitt 2008-06-20 16:41:08 +00:00
parent e952fa42b0
commit cbb925d4cb
5 changed files with 73 additions and 44 deletions

View File

@ -2888,6 +2888,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
m->pacifier_interval= 1.0; m->pacifier_interval= 1.0;
m->pacifier_count= 0; m->pacifier_count= 0;
m->pacifier_total= 0; m->pacifier_total= 0;
m->pacifier_byte_count= 0;
m->pacifier_fifo= NULL; m->pacifier_fifo= NULL;
m->start_time= 0.0; m->start_time= 0.0;
m->last_update_time= 0.0; m->last_update_time= 0.0;
@ -3346,6 +3347,7 @@ int Xorriso_pacifier_reset(struct XorrisO *xorriso, int flag)
xorriso->last_update_time= xorriso->start_time; xorriso->last_update_time= xorriso->start_time;
xorriso->pacifier_count= 0; xorriso->pacifier_count= 0;
xorriso->pacifier_total= 0; xorriso->pacifier_total= 0;
xorriso->pacifier_byte_count= 0;
return(1); return(1);
} }
@ -3363,6 +3365,7 @@ int Xorriso_pacifier_reset(struct XorrisO *xorriso, int flag)
Ignored if "". Ignored if "".
@param flag bit0= report unconditionally, no time check @param flag bit0= report unconditionally, no time check
bit1= report count <=0 (no thank you for being patient then) bit1= report count <=0 (no thank you for being patient then)
bit2= report xorriso->pacifier_byte_count
bit6= report with carriage return rather than line feed bit6= report with carriage return rather than line feed
*/ */
int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done, int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done,
@ -3370,7 +3373,7 @@ int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done,
int flag) int flag)
{ {
double current_time, since; double current_time, since;
char count_text[80]; char count_text[80], byte_text[80];
current_time= Sfile_microtime(0); current_time= Sfile_microtime(0);
if(current_time - xorriso->last_update_time < xorriso->pacifier_interval if(current_time - xorriso->last_update_time < xorriso->pacifier_interval
@ -3380,6 +3383,13 @@ int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done,
since= current_time - xorriso->start_time; since= current_time - xorriso->start_time;
if((flag&1)&&since<1.0) if((flag&1)&&since<1.0)
since= 1.0; since= 1.0;
byte_text[0]= 0;
if(flag&4) {
strcat(byte_text, " (");
Sfile_scale((double) xorriso->pacifier_byte_count,
byte_text+strlen(byte_text), 7, 1e5, 0);
strcat(byte_text, ")");
}
if(count<=0.0 && !(flag&2)) { if(count<=0.0 && !(flag&2)) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Thank you for being patient since %.f seconds", since); "Thank you for being patient since %.f seconds", since);
@ -3388,11 +3398,11 @@ int Xorriso_pacifier_callback(struct XorrisO *xorriso, char *what_done,
sprintf(count_text, "%.f", (double) count); sprintf(count_text, "%.f", (double) count);
else else
Sfile_scale((double) count, count_text, 7, 1e5, 1); Sfile_scale((double) count, count_text, 7, 1e5, 1);
sprintf(xorriso->info_text, "%s %s in %.f %s", sprintf(xorriso->info_text, "%s %s%s in %.f %s",
count_text, what_done, since, (flag&64) ? "s" : "seconds"); count_text, what_done, byte_text, since, (flag&64) ? "s" : "seconds");
} else { } else {
sprintf(xorriso->info_text, "%.f of %.f %s in %.f seconds", sprintf(xorriso->info_text, "%.f of %.f %s%s in %.f seconds",
(double) count, (double) todo, what_done, since); (double) count, (double) todo, what_done, byte_text, since);
} }
if(current_object[0]!=0) if(current_object[0]!=0)
sprintf(xorriso->info_text+strlen(xorriso->info_text), sprintf(xorriso->info_text+strlen(xorriso->info_text),
@ -4358,7 +4368,7 @@ cannot_address:;
goto cannot_address; goto cannot_address;
} }
ret= Xorriso_iso_file_open(xorriso, iso_adr, &stream2, 0); ret= Xorriso_iso_file_open(xorriso, iso_adr, NULL, &stream2, 0);
if(ret<=0) { if(ret<=0) {
sprintf(respt, "- %s (ISO) : cannot open() file in ISO image\n", iso_adr); sprintf(respt, "- %s (ISO) : cannot open() file in ISO image\n", iso_adr);
if(!(flag&(1<<31))) if(!(flag&(1<<31)))
@ -4451,6 +4461,7 @@ cannot_address:;
} }
if(!(flag&(1<<29))) { if(!(flag&(1<<29))) {
xorriso->pacifier_count+= r1; xorriso->pacifier_count+= r1;
xorriso->pacifier_byte_count+= r1;
if(flag&(1<<31)) if(flag&(1<<31))
Xorriso_pacifier_callback(xorriso, "content bytes read", Xorriso_pacifier_callback(xorriso, "content bytes read",
xorriso->pacifier_count, 0, "", 0); xorriso->pacifier_count, 0, "", 0);
@ -8929,7 +8940,7 @@ problem_handler:;
} }
if(xorriso->pacifier_count>0) if(xorriso->pacifier_count>0)
Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count, Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count,
xorriso->pacifier_total, "", 1); xorriso->pacifier_total, "", 1|4);
ret= !was_failure; ret= !was_failure;
ex:; ex:;
Xorriso_opt_args(xorriso, "-cp*x", Xorriso_opt_args(xorriso, "-cp*x",
@ -9303,7 +9314,7 @@ int Xorriso_option_extract(struct XorrisO *xorriso, char *iso_path,
(off_t) 0, (off_t) 0, (flag&32)); (off_t) 0, (off_t) 0, (flag&32));
if(!(flag&2)) if(!(flag&2))
Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count, Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count,
xorriso->pacifier_total, "", 1); xorriso->pacifier_total, "", 1|4);
if(ret<=0) if(ret<=0)
return(ret); return(ret);
@ -10414,7 +10425,7 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag) int *idx, int flag)
{ {
int ret, end_idx, optc= 0, was_failure= 1, i, fret, mode; int ret, end_idx, optc= 0, was_failure= 1, i, fret, mode;
int ns_flag= 2|4, nt_flag= 2; int ns_flag= 2|4, nt_flag= 2, opt_args_flag= 2;
char source_prefix[SfileadrL], target_prefix[SfileadrL], *cmd, **optv= NULL; char source_prefix[SfileadrL], target_prefix[SfileadrL], *cmd, **optv= NULL;
char eff_source[SfileadrL], eff_target[SfileadrL], *source_pt, *s_wd, *t_wd; char eff_source[SfileadrL], eff_target[SfileadrL], *source_pt, *s_wd, *t_wd;
char sfe[5*SfileadrL]; char sfe[5*SfileadrL];
@ -10435,6 +10446,7 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
s_wd= xorriso->wdi; s_wd= xorriso->wdi;
nt_flag= 2|4; nt_flag= 2|4;
t_wd= xorriso->wdx; t_wd= xorriso->wdx;
opt_args_flag= 0;
} }
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2); end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2);
@ -10445,7 +10457,7 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
ret= 0; goto ex; ret= 0; goto ex;
} }
ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[*idx], ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[*idx],
source_prefix, ns_flag); source_prefix, ns_flag | 64);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
ret= Xorriso_normalize_img_path(xorriso, t_wd, argv[(*idx)+1], ret= Xorriso_normalize_img_path(xorriso, t_wd, argv[(*idx)+1],
@ -10453,7 +10465,7 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
if(ret<=0) if(ret<=0)
goto ex; goto ex;
ret= Xorriso_opt_args(xorriso, cmd, argc, argv, (*idx)+2, &end_idx, ret= Xorriso_opt_args(xorriso, cmd, argc, argv, (*idx)+2, &end_idx,
&optc, &optv, 2); &optc, &optv, opt_args_flag);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
@ -10490,7 +10502,7 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
ret= Xorriso_option_compare(xorriso, eff_source, eff_target, 2|8); ret= Xorriso_option_compare(xorriso, eff_source, eff_target, 2|8);
else if(mode==2) else if(mode==2)
ret= Xorriso_option_update(xorriso, eff_source, eff_target, 2|8); ret= Xorriso_option_update(xorriso, eff_source, eff_target, 2|8);
else if(mode==2) else if(mode==3)
ret= Xorriso_option_extract(xorriso, eff_source, eff_target, 2); ret= Xorriso_option_extract(xorriso, eff_source, eff_target, 2);
if(ret>0 && !xorriso->request_to_abort) if(ret>0 && !xorriso->request_to_abort)
@ -10509,7 +10521,7 @@ int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
xorriso->pacifier_count, 0, "", 1); xorriso->pacifier_count, 0, "", 1);
else if(mode==3) else if(mode==3)
Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count, Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count,
xorriso->pacifier_total, "", 1); xorriso->pacifier_total, "", 1|4);
ret= 1; ret= 1;
ex:; ex:;
(*idx)= end_idx; (*idx)= end_idx;

View File

@ -262,6 +262,7 @@ struct XorrisO { /* the global context of xorriso */
/* optional global counters for brain reduced callback functions */ /* optional global counters for brain reduced callback functions */
off_t pacifier_count; off_t pacifier_count;
off_t pacifier_total; off_t pacifier_total;
off_t pacifier_byte_count; /* auxiliary counter for data bytes */
void *pacifier_fifo; void *pacifier_fifo;

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.06.20.091647" #define Xorriso_timestamP "2008.06.20.164105"

View File

@ -1253,6 +1253,7 @@ int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume,
bit4= (with bit2) determine type of disk file eff_path bit4= (with bit2) determine type of disk file eff_path
and return 0 if not existing and return 0 if not existing
bit5= (with bit3) this is not a parameter bit5= (with bit3) this is not a parameter
bit6= insist in having an ISO image, even with bits1+2
@return -1 = faulty path format, 0 = not found , @return -1 = faulty path format, 0 = not found ,
1 = found simple node , 2 = found directory 1 = found simple node , 2 = found directory
*/ */
@ -1265,6 +1266,12 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
IsoNode *node= NULL; IsoNode *node= NULL;
char path[SfileadrL], *apt, *npt, sfe[5*SfileadrL], *cpt; char path[SfileadrL], *apt, *npt, sfe[5*SfileadrL], *cpt;
if((flag&64) || !(flag&2)) {
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
}
eff_path[0]= 0; eff_path[0]= 0;
if(img_path[0]==0) { if(img_path[0]==0) {
if(flag&8) if(flag&8)
@ -1272,12 +1279,6 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
return(2); /* root directory */ return(2); /* root directory */
} }
if(!(flag&2)) {
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
}
apt= npt= path; apt= npt= path;
if(img_path[0]!='/') { if(img_path[0]!='/') {
strcpy(path, wd); strcpy(path, wd);
@ -1473,7 +1474,7 @@ int Xorriso_fake_stbuf(struct XorrisO *xorriso, char *path, struct stat *stbuf,
} }
/* @param flag >>> bit0= follow links (i.e. stat() rather than lstat() /* @param flag >>> bit0= follow links (i.e. stat() rather than lstat()
bit1= do not return -2 on severe errors bit1= do not return -2 on severe errors
bit2= complain loudely if path is missing in image bit2= complain loudely if path is missing in image
*/ */
@ -1621,6 +1622,8 @@ ex:;
"Cannot add node to tree", 0, "FAILURE", 1|2); "Cannot add node to tree", 0, "FAILURE", 1|2);
return(ret); return(ret);
} }
if(LIBISO_ISREG(*node))
xorriso->pacifier_byte_count+= iso_file_get_size((IsoFile *) *node);
return(1); return(1);
} }
@ -2469,6 +2472,7 @@ int Xorriso_restore_implicit_properties(struct XorrisO *xorriso,
bit1= offset and bytes is valid for writing to regular file bit1= offset and bytes is valid for writing to regular file
bit2= This is not a parameter. Do not report if ignored bit2= This is not a parameter. Do not report if ignored
bit3= do not restore properties bit3= do not restore properties
bit4= issue pacifier messages with long lasting copying
@return <0 severe error , 0 failure , 1 success , @return <0 severe error , 0 failure , 1 success ,
2 regularly not installed (disallowed device, UNIX domain socket) 2 regularly not installed (disallowed device, UNIX domain socket)
*/ */
@ -2480,7 +2484,7 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
char *what= "[unknown filetype]", sfe[5*SfileadrL], sfe2[5*SfileadrL]; char *what= "[unknown filetype]", sfe[5*SfileadrL], sfe2[5*SfileadrL];
char buf[32*1024], type_text[5], temp_path[SfileadrL]; char buf[32*1024], type_text[5], temp_path[SfileadrL];
char *link_target, *open_path_pt; char *link_target, *open_path_pt;
off_t todo, size, seek_ret; off_t todo, size, seek_ret, last_p_count= 0;
void *data_stream= NULL; void *data_stream= NULL;
mode_t mode; mode_t mode;
dev_t dev= 0; dev_t dev= 0;
@ -2493,13 +2497,10 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
} else if(LIBISO_ISREG(node)) { } else if(LIBISO_ISREG(node)) {
what= "regular file"; what= "regular file";
ret= Xorriso_iso_file_open(xorriso, img_path, (void *) node, &data_stream,
/* >>> need to exploit node rather than img_path */ 1);
ret= Xorriso_iso_file_open(xorriso, img_path, &data_stream, 0);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
open_path_pt= disk_path; open_path_pt= disk_path;
ret= stat(open_path_pt, &stbuf); ret= stat(open_path_pt, &stbuf);
if(flag&2) { if(flag&2) {
@ -2560,8 +2561,17 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
if(ret<=0) if(ret<=0)
break; break;
wret= write(write_fd, buf, ret); wret= write(write_fd, buf, ret);
if(wret>=0) if(wret>=0) {
todo-= wret; todo-= wret;
xorriso->pacifier_byte_count+= wret;
if((flag&16) &&
xorriso->pacifier_byte_count - last_p_count >= 128*1024) {
Xorriso_pacifier_callback(xorriso, "files restored",
xorriso->pacifier_count,
xorriso->pacifier_total, "", 2|4);
last_p_count= xorriso->pacifier_byte_count;
}
}
if(wret != ret) { if(wret != ret) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Cannot write all bytes to disk filesystem path %s", "Cannot write all bytes to disk filesystem path %s",
@ -2728,7 +2738,7 @@ int Xorriso_restore_disk_object(struct XorrisO *xorriso,
off_t offset, off_t bytes, int flag) off_t offset, off_t bytes, int flag)
{ {
int ret, i, split_count= 0, partno, total_parts, leaf_is_split= 0; int ret, i, split_count= 0, partno, total_parts, leaf_is_split= 0;
off_t total_bytes; off_t total_bytes, was_byte_count;
char *part_name, part_path[SfileadrL], *img_path_pt; char *part_name, part_path[SfileadrL], *img_path_pt;
char sfe[5*SfileadrL], sfe2[5*SfileadrL]; char sfe[5*SfileadrL], sfe2[5*SfileadrL];
IsoImage *volume; IsoImage *volume;
@ -2739,6 +2749,8 @@ int Xorriso_restore_disk_object(struct XorrisO *xorriso,
ret= Xorriso_get_volume(xorriso, &volume, 0); ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
was_byte_count= xorriso->pacifier_byte_count;
if(LIBISO_ISDIR(node) && xorriso->do_concat_split) if(LIBISO_ISDIR(node) && xorriso->do_concat_split)
leaf_is_split= Xorriso_identify_split(xorriso, img_path, node, leaf_is_split= Xorriso_identify_split(xorriso, img_path, node,
@ -2763,8 +2775,8 @@ int Xorriso_restore_disk_object(struct XorrisO *xorriso,
if(offset+bytes>total_bytes) if(offset+bytes>total_bytes)
bytes= total_bytes-offset; bytes= total_bytes-offset;
ret= Xorriso_tree_restore_node(xorriso, part_node, part_path, disk_path, ret= Xorriso_tree_restore_node(xorriso, part_node, part_path, disk_path,
offset, bytes, offset, bytes,
(!!(flag&64)) | 2 | (flag&4) | 8); (!!(flag&64)) | 2 | (flag&4) | 8 | ( 16 * !(flag&2)));
if(ret<=0) if(ret<=0)
goto restoring_failed; goto restoring_failed;
} }
@ -2788,8 +2800,8 @@ int Xorriso_restore_disk_object(struct XorrisO *xorriso,
img_path_pt= img_path; img_path_pt= img_path;
ret= Xorriso_tree_restore_node(xorriso, node, img_path_pt, disk_path, ret= Xorriso_tree_restore_node(xorriso, node, img_path_pt, disk_path,
offset, bytes, offset, bytes,
(flag&(4|8)) | (!!(flag&64)) | ((flag&1)<<1)); (flag&(4|8)) | (!!(flag&64)) | ((flag&1)<<1) | ( 16 * !(flag&2)));
if(ret>0 && (flag&8)) if(ret>0 && (flag&8))
ret= Xorriso_restore_properties(xorriso, disk_path, node, 2 | !!(flag&64)); ret= Xorriso_restore_properties(xorriso, disk_path, node, 2 | !!(flag&64));
if(ret<=0) { if(ret<=0) {
@ -2803,10 +2815,10 @@ restoring_failed:;
{ret= 3; goto ex;} {ret= 3; goto ex;}
went_well:; went_well:;
xorriso->pacifier_count++; xorriso->pacifier_count++;
if(xorriso->pacifier_count%100 && !(flag&2)) if(!(flag&2))
Xorriso_pacifier_callback(xorriso, "files restored", Xorriso_pacifier_callback(xorriso, "files restored",
xorriso->pacifier_count, xorriso->pacifier_count,
xorriso->pacifier_total, "", 0); xorriso->pacifier_total, "", 4);
ret= 1; ret= 1;
ex:; ex:;
if(split_parts!=NULL) if(split_parts!=NULL)
@ -3221,11 +3233,9 @@ int Xorriso_restore(struct XorrisO *xorriso,
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);
Xorriso_report_iso_error(xorriso, disk_path, ret,
"Cannot create disk directory", 0, "FAILURE", 1);
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"While restoring '%s' : could not insert '%s'", disk_path, path); "While restoring '%s' : could not insert '%s'", disk_path, path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
{ret= 0; goto ex;} {ret= 0; goto ex;}
} }
if(!done) { if(!done) {
@ -3235,7 +3245,7 @@ int Xorriso_restore(struct XorrisO *xorriso,
} }
new_dir_made= 1; new_dir_made= 1;
} else if(source_is_dir && !source_is_split) { } else if(source_is_dir && !source_is_split) {
Xorriso_auto_chmod(xorriso, disk_path, 0); Xorriso_auto_chmod(xorriso, path, 0);
} }
if(done) { if(done) {
attach_source:; attach_source:;
@ -6071,7 +6081,7 @@ int Xorriso_get_profile(struct XorrisO *xorriso, int *profile_number,
int Xorriso_iso_file_open(struct XorrisO *xorriso, char *pathname, int Xorriso_iso_file_open(struct XorrisO *xorriso, char *pathname,
void **stream, int flag) void *node_pt, void **stream, int flag)
{ {
int ret; int ret;
char eff_path[SfileadrL]; char eff_path[SfileadrL];
@ -6087,9 +6097,13 @@ int Xorriso_iso_file_open(struct XorrisO *xorriso, char *pathname,
#endif #endif
*stream= NULL; *stream= NULL;
ret= Xorriso_get_node_by_path(xorriso, pathname, eff_path, &node, 0); if(flag&1) {
if(ret<=0) node= (IsoNode *) node_pt;
return(ret); } else {
ret= Xorriso_get_node_by_path(xorriso, pathname, eff_path, &node, 0);
if(ret<=0)
return(ret);
}
if(!LIBISO_ISREG(node)) { if(!LIBISO_ISREG(node)) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Given path does not lead to a regular data file in the image"); "Given path does not lead to a regular data file in the image");

View File

@ -200,8 +200,10 @@ int Xorriso_get_profile(struct XorrisO *xorriso, int *profile_number,
int Xorriso_set_publisher(struct XorrisO *xorriso, char *name, int flag); int Xorriso_set_publisher(struct XorrisO *xorriso, char *name, int flag);
/* @param flag bit0= node_pt is a valid ISO object handle, ignore pathname
*/
int Xorriso_iso_file_open(struct XorrisO *xorriso, char *pathname, int Xorriso_iso_file_open(struct XorrisO *xorriso, char *pathname,
void **stream, int flag); void *node_pt, void **stream, int flag);
int Xorriso_iso_file_read(struct XorrisO *xorriso, void *stream, char *buf, int Xorriso_iso_file_read(struct XorrisO *xorriso, void *stream, char *buf,
int count, int flag); int count, int flag);