Working towards coordination of -update and -cut_out

This commit is contained in:
Thomas Schmitt 2008-03-27 10:34:06 +00:00
parent f9afb4a2f9
commit 7ea03c4079
3 changed files with 153 additions and 42 deletions

View File

@ -599,6 +599,50 @@ int Sfile_scale(double value, char *result, int siz, double thresh, int flag)
} }
int Sfile_off_t_text(char text[80], off_t num, int flag)
{
char *tpt;
off_t hnum, scale= 1;
int digits= 0, d, i;
tpt= text;
hnum= num;
if(hnum<0) {
*(tpt++)= '-';
hnum= -num;
}
if(hnum<0) { /* it can stay nastily persistent */
strcpy(text, "_overflow_");
return(0);
}
for(i= 0; i<23; i++) { /* good for up to 70 bit = 10 exp 21.07... */
if(hnum==0)
break;
hnum/= 10;
if(hnum)
scale*= 10;
}
if(i==0) {
strcpy(text, "0");
return(1);
}
if(i==23) {
strcpy(text, "_overflow_");
return(0);
}
digits= i;
hnum= num;
for(; i>0; i--) {
d= hnum/scale;
tpt[digits-i]= '0'+d;
hnum= hnum%scale;
scale/= 10;
}
tpt[digits]= 0;
return(1);
}
int Sfile_destroy_argv(int *argc, char ***argv, int flag) int Sfile_destroy_argv(int *argc, char ***argv, int flag)
{ {
int i; int i;
@ -2856,6 +2900,27 @@ int Splitpart__parse(char *name, int *partno, int *total_parts,
} }
int Splitpart__compose(char *adr, int partno, int total_parts,
off_t offset, off_t bytes, off_t total_bytes, int flag)
{
sprintf(adr, "part_%d_of_%d_at_", partno, total_parts);
if((offset % (1024*1024))==0 && offset>0) {
Sfile_off_t_text(adr+strlen(adr), offset / (1024*1024), 0);
strcat(adr, "m");
} else
Sfile_off_t_text(adr+strlen(adr), offset, 0);
strcat(adr, "_with_");
if((bytes % (1024*1024))==0) {
Sfile_off_t_text(adr+strlen(adr), bytes / (1024*1024), 0);
strcat(adr, "m");
} else
Sfile_off_t_text(adr+strlen(adr), bytes, 0);
strcat(adr, "_of_");
Sfile_off_t_text(adr+strlen(adr), total_bytes, 0);
return(1);
}
/* ---------------------------- End SplitparT ------------------------- */ /* ---------------------------- End SplitparT ------------------------- */
/* ------------------------------- Xorriso -------------------------------- */ /* ------------------------------- Xorriso -------------------------------- */
@ -7525,14 +7590,14 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
int compare_result, char *disk_path, int compare_result, char *disk_path,
char *iso_rr_path, int flag) char *iso_rr_path, int flag)
{ {
int ret, deleted= 0, is_split= 0, i; int ret, deleted= 0, is_split= 0, i, loop_count;
char sfe[5*SfileadrL]; char sfe[5*SfileadrL];
struct stat stbuf; struct stat stbuf;
struct SplitparT *split_parts= NULL; struct SplitparT *split_parts= NULL;
int split_count= 0; int split_count= 0;
char part_path[SfileadrL], *part_name; char part_path[SfileadrL], *part_name;
int partno, total_parts; int partno, total_parts, new_total_parts;
off_t offset, bytes, total_bytes; off_t offset, bytes, total_bytes, disk_size, first_bytes;
if(compare_result&((1<<11)|(1<<13))) { if(compare_result&((1<<11)|(1<<13))) {
/* cannot open regular disk file, early eof of disk file */ /* cannot open regular disk file, early eof of disk file */
@ -7546,7 +7611,7 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
is_split= !!(compare_result & (1<<17)); is_split= !!(compare_result & (1<<17));
/* <<< */ /* <<< */
if(is_split) { if(0 && is_split) {
sprintf(xorriso->info_text, "Split file cannot be updated yet: %s\n", sprintf(xorriso->info_text, "Split file cannot be updated yet: %s\n",
Text_shellsafe(iso_rr_path, sfe, 0)); Text_shellsafe(iso_rr_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 1); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 1);
@ -7567,12 +7632,8 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
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)) {
delete:;
/* disk_adr not existing */ /* disk_adr not existing */
/* ??? SPLIT : Shall i recognize a splitfile without disk file ?
Does it make any difference ?
*/
ret= Xorriso_rmi(xorriso, boss_iter, (off_t) 0, iso_rr_path, 1); ret= Xorriso_rmi(xorriso, boss_iter, (off_t) 0, iso_rr_path, 1);
deleted= 1; deleted= 1;
sprintf(xorriso->info_text, "Deleted "); sprintf(xorriso->info_text, "Deleted ");
@ -7587,7 +7648,25 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
&split_parts, &split_count, &stbuf, 0); &split_parts, &split_count, &stbuf, 0);
if(ret<=0) if(ret<=0)
{ret= -1; goto ex;} /* (should not happen) */ {ret= -1; goto ex;} /* (should not happen) */
for(i= 0; i<split_count; i++) { ret= lstat(disk_path, &stbuf);
if(ret==-1)
goto delete;
disk_size= stbuf.st_size;
Splitparts_get(split_parts, 0, &part_name, &partno, &total_parts,
&offset, &first_bytes, &total_bytes, 0);
new_total_parts= disk_size/first_bytes;
if(disk_size % first_bytes)
new_total_parts++;
loop_count= split_count;
/* If disk file grew over part limit and all parts are present:
add new parts */
if(new_total_parts > total_parts && split_count == total_parts)
loop_count= new_total_parts;
for(i= 0; i<loop_count; i++) {
if(i<split_count) {
/* Delete old part */
Splitparts_get(split_parts, i, &part_name, &partno, &total_parts, Splitparts_get(split_parts, i, &part_name, &partno, &total_parts,
&offset, &bytes, &total_bytes, 0); &offset, &bytes, &total_bytes, 0);
strcpy(part_path, iso_rr_path); strcpy(part_path, iso_rr_path);
@ -7596,22 +7675,31 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
strlen(iso_rr_path)+strlen(part_path)+1, 2); strlen(iso_rr_path)+strlen(part_path)+1, 2);
{ret= -1; goto ex;} {ret= -1; goto ex;}
} }
/* Delete old part, just in case the name changes */
ret= Xorriso_rmi(xorriso, NULL, (off_t) 0, part_path, 1); ret= Xorriso_rmi(xorriso, NULL, (off_t) 0, part_path, 1);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
/* overwrite by new parts resp. delete from directory */ } else {
partno= i+1;
offset= i*first_bytes;
}
if(disk_size<=offset)
continue;
/* Insert new part */
if(strlen(part_path)+160>SfileadrL) {
Xorriso_much_too_long(xorriso, strlen(part_path)+160, 2);
ret= 0; goto ex;
}
Splitpart__compose(part_path+strlen(iso_rr_path)+1, partno,
new_total_parts, offset, first_bytes, disk_size, 0);
ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, part_path, ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, part_path,
offset, bytes, 2|(flag&4)); offset, bytes, 2|(flag&4)|8);
if(ret<=0) if(ret<=0)
goto ex; goto ex;
} }
/* Copy file attributes to iso_rr_path, augment r-perms by x-perms */
/* >>> ??? if disk file grew over part limit : add part ? */; ret= Xorriso_copy_properties(xorriso, disk_path, iso_rr_path, 2);
if(ret<=0)
/* >>> copy file attributes to iso_rr_path */; goto ex;
} else } else
ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, iso_rr_path, ret= Xorriso_graft_in(xorriso, boss_iter, disk_path, iso_rr_path,
(off_t) 0, (off_t) 0, 2|(flag&4)); (off_t) 0, (off_t) 0, 2|(flag&4));
@ -7638,9 +7726,10 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso, void *boss_iter,
if(ret<=0) if(ret<=0)
goto ex; goto ex;
} }
/* Copy file attributes to iso_rr_path, augment r-perms by x-perms */
/* >>> copy file attributes to iso_rr_path */; ret= Xorriso_copy_properties(xorriso, disk_path, iso_rr_path, 2);
if(ret<=0)
goto ex;
} else } else
ret= Xorriso_copy_properties(xorriso, disk_path, iso_rr_path, 0); ret= Xorriso_copy_properties(xorriso, disk_path, iso_rr_path, 0);
sprintf(xorriso->info_text, "Adjusted attributes of "); sprintf(xorriso->info_text, "Adjusted attributes of ");
@ -8547,7 +8636,7 @@ ex:;
} }
/* >>> SPLIT : proposed target format /* SPLIT : proposed target format
part_{partno}_of_{total_parts}_at_{offset}_with_{bytes}_of_{total_bytes} part_{partno}_of_{total_parts}_at_{offset}_with_{bytes}_of_{total_bytes}
*/ */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.03.26.092120" #define Xorriso_timestamP "2008.03.27.103344"

View File

@ -1358,10 +1358,23 @@ int Xorriso_get_node_by_path(struct XorrisO *xorriso,
} }
/* @param flag bit0= give directory x-permission where is r-permission
*/
int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf, int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
IsoNode *node, int flag) IsoNode *node, int flag)
{ {
iso_node_set_permissions(node, stbuf->st_mode & 07777); mode_t mode;
mode= stbuf->st_mode;
if((flag&1) && S_ISDIR(mode)) {
if(mode&S_IRUSR)
mode|= S_IXUSR;
if(mode&S_IRGRP)
mode|= S_IXGRP;
if(mode&S_IROTH)
mode|= S_IXOTH;
}
iso_node_set_permissions(node, mode & 07777);
iso_node_set_uid(node, stbuf->st_uid); iso_node_set_uid(node, stbuf->st_uid);
iso_node_set_gid(node, stbuf->st_gid); iso_node_set_gid(node, stbuf->st_gid);
iso_node_set_atime(node, stbuf->st_atime); iso_node_set_atime(node, stbuf->st_atime);
@ -1699,6 +1712,8 @@ int Xorriso_copy_implict_properties(struct XorrisO *xorriso, IsoDir *dir,
strcpy(nfd, "/"); strcpy(nfd, "/");
if(stat(nfd, &stbuf)==-1) if(stat(nfd, &stbuf)==-1)
return(0); return(0);
#ifdef NIX
if((flag&1) && d==0) { if((flag&1) && d==0) {
/* give directory x-permission where is r-permission */ /* give directory x-permission where is r-permission */
if(stbuf.st_mode&S_IRUSR) if(stbuf.st_mode&S_IRUSR)
@ -1708,7 +1723,12 @@ int Xorriso_copy_implict_properties(struct XorrisO *xorriso, IsoDir *dir,
if(stbuf.st_mode&S_IROTH) if(stbuf.st_mode&S_IROTH)
stbuf.st_mode|= S_IXOTH; stbuf.st_mode|= S_IXOTH;
} }
Xorriso_transfer_properties(xorriso, &stbuf, (IsoNode *) dir, 0); Xorriso_transfer_properties(xorriso, &stbuf, (IsoNode *) dir, flag&1);
#else
Xorriso_transfer_properties(xorriso, &stbuf, (IsoNode *) dir,
((flag&1) && d==0));
#endif /* ! NIX */
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Copied properties for %s", Text_shellsafe(ni, sfe, 0)); "Copied properties for %s", Text_shellsafe(ni, sfe, 0));
sprintf(xorriso->info_text+strlen(xorriso->info_text), sprintf(xorriso->info_text+strlen(xorriso->info_text),
@ -1720,6 +1740,7 @@ int Xorriso_copy_implict_properties(struct XorrisO *xorriso, IsoDir *dir,
/* @param bit0= copy link target properties rather than link properties /* @param bit0= copy link target properties rather than link properties
bit1= give directory x-permission where is r-permission
*/ */
int Xorriso_copy_properties(struct XorrisO *xorriso, int Xorriso_copy_properties(struct XorrisO *xorriso,
char *disk_path, char *img_path, int flag) char *disk_path, char *img_path, int flag)
@ -1733,7 +1754,7 @@ int Xorriso_copy_properties(struct XorrisO *xorriso,
return(ret); return(ret);
if(lstat(disk_path, &stbuf)==-1) if(lstat(disk_path, &stbuf)==-1)
return(0); return(0);
Xorriso_transfer_properties(xorriso, &stbuf, node, 0); Xorriso_transfer_properties(xorriso, &stbuf, node, (flag&2)>>1);
xorriso->volset_change_pending= 1; xorriso->volset_change_pending= 1;
return(1); return(1);
} }
@ -4677,7 +4698,7 @@ int Xorriso_identify_split(struct XorrisO *xorriso, char *iso_adr,
{ {
int ret, i; int ret, i;
int partno, total_parts, first_total_parts= -1; int partno, total_parts, first_total_parts= -1;
off_t offset, bytes, total_bytes, first_total_bytes= -1, size; off_t offset, bytes, total_bytes, first_total_bytes= -1, first_bytes, size;
IsoImage *volume; IsoImage *volume;
IsoDir *dir_node; IsoDir *dir_node;
IsoDirIter *iter= NULL; IsoDirIter *iter= NULL;
@ -4713,25 +4734,26 @@ cannot_iter:;
{ret= 0; goto ex;} {ret= 0; goto ex;}
if(i==0) { if(i==0) {
first_total_parts= total_parts; first_total_parts= total_parts;
first_bytes= bytes;
first_total_bytes= total_bytes; first_total_bytes= total_bytes;
Xorriso_fake_stbuf(xorriso, "", &first_stbuf, &node, 1); Xorriso_fake_stbuf(xorriso, "", &first_stbuf, &node, 1);
size= first_stbuf.st_size; size= first_stbuf.st_size;
} else { } else {
if(first_total_parts!=total_parts || first_total_bytes!=total_bytes) if(first_total_parts!=total_parts || first_total_bytes!=total_bytes ||
(first_bytes!=bytes && partno!=total_parts))
{ret= 0; goto ex;} {ret= 0; goto ex;}
Xorriso_fake_stbuf(xorriso, "", &stbuf, &node, 1); Xorriso_fake_stbuf(xorriso, "", &stbuf, &node, 1);
if(first_stbuf.st_mode != stbuf.st_mode || if(first_stbuf.st_mode != stbuf.st_mode ||
first_stbuf.st_uid != stbuf.st_uid || first_stbuf.st_uid != stbuf.st_uid ||
first_stbuf.st_gid != stbuf.st_gid || first_stbuf.st_gid != stbuf.st_gid ||
first_stbuf.st_mtime != stbuf.st_mtime || first_stbuf.st_mtime != stbuf.st_mtime ||
first_stbuf.st_ctime != stbuf.st_ctime || first_stbuf.st_ctime != stbuf.st_ctime)
first_stbuf.st_atime != stbuf.st_atime)
{ret= 0; goto ex;} {ret= 0; goto ex;}
size= stbuf.st_size; size= stbuf.st_size;
} }
/* check for plausible size */ /* check for plausible size */
if(!((partno<total_parts && size==bytes) || if(!((partno<total_parts && size==bytes) ||
(partno==total_parts && size==(total_bytes-offset) && size<=bytes))) (partno==total_parts && size<=bytes)))
{ret= 0; goto ex;} {ret= 0; goto ex;}
(*count)++; (*count)++;
} }