New option -paste_in

This commit is contained in:
2008-06-13 15:16:03 +00:00
parent 0d407b63ad
commit 26b3dcb1f5
6 changed files with 140 additions and 77 deletions

View File

@ -2257,7 +2257,7 @@ unsupported_type:;
}
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, iso_rr_path, eff_dest,
2|((flag&1)<<2));
2);
if(ret<=0)
return(ret);
@ -2536,8 +2536,10 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
if(write_fd==-1)
goto cannot_restore;
}
todo= size= iso_file_get_size((IsoFile *) node);
if(flag&2) {
todo= size= bytes;
if(bytes<size)
todo= size= bytes;
seek_ret= lseek(write_fd, offset, SEEK_SET);
if(seek_ret == -1) {
sprintf(xorriso->info_text,
@ -2546,8 +2548,7 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE",0);
goto cannot_restore;
}
} else
todo= size= iso_file_get_size((IsoFile *) node);
}
while(todo>0) {
wanted= sizeof(buf);
if(wanted>todo)
@ -2711,7 +2712,7 @@ int Xorriso_restore_overwrite(struct XorrisO *xorriso,
/*
@param flag
@param flag bit0= offset and bytes is valid for writing to regular file
bit1= do not report copied files
bit2= -follow, -not_*: this is not a command parameter
bit3= keep directory open: keep owner, allow rwx for owner
@ -2721,10 +2722,10 @@ int Xorriso_restore_overwrite(struct XorrisO *xorriso,
int Xorriso_restore_disk_object(struct XorrisO *xorriso,
char *img_path, IsoNode *node,
char *disk_path,
int flag)
off_t offset, off_t bytes, int flag)
{
int ret, i, split_count= 0, partno, total_parts, leaf_is_split= 0;
off_t offset, bytes, total_bytes;
off_t total_bytes;
char *part_name, part_path[SfileadrL], *img_path_pt;
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
IsoImage *volume;
@ -2784,8 +2785,8 @@ int Xorriso_restore_disk_object(struct XorrisO *xorriso,
img_path_pt= img_path;
ret= Xorriso_tree_restore_node(xorriso, node, img_path_pt, disk_path,
(off_t) 0, (off_t) 0,
(flag&(4|8)) | !!(flag&64));
offset, bytes,
(flag&(4|8)) | (!!(flag&64)) | ((flag&1)<<1));
if(ret>0 && (flag&8))
ret= Xorriso_restore_properties(xorriso, disk_path, node, 2 | !!(flag&64));
if(ret<=0) {
@ -3037,35 +3038,11 @@ much_too_long:;
source_is_split= Xorriso_is_split(xorriso, img_path, node, 1|2);
if(source_is_split)
do_not_dive= 1;
#ifdef NIX
/* >>> handle softlinks */;
/* does a disk file exist with this name ? */
stbuf_ret= lstat(disk_path, &target_stbuf);
if(stbuf_ret!=-1) {
target_is_dir= S_ISDIR(target_stbuf.st_mode);
if(!(target_is_dir && (source_is_dir && !source_is_split))) {
Xorriso_process_msg_queues(xorriso,0);
ret= Xorriso_restore_overwrite(xorriso, node, img_path, disk_path,
disk_path, &target_stbuf, 0);
if(ret<=0)
goto was_problem;
stbuf_ret= -1; /* It might still exist but will be handled properly */
}
}
#else /* NIX */
ret= Xorriso_handle_collision(xorriso, node, img_path, disk_path, disk_path,
&stbuf_ret, (source_is_dir && !source_is_split));
if(ret<=0 || ret==3)
goto was_problem;
#endif /* ! NIX */
if(stbuf_ret!=-1) { /* (Can only happen with directory) */
/* ??? >>> eventually open access to existing directory ? */;
@ -3075,7 +3052,7 @@ much_too_long:;
if(source_is_dir && !do_not_dive)
hflag|= 8; /* keep directory open for user */
ret= Xorriso_restore_disk_object(xorriso, img_path, node, disk_path,
hflag);
(off_t) 0, (off_t) 0, hflag);
if(ret<=0)
goto was_problem;
}
@ -3136,7 +3113,7 @@ ex:
>>> bit0= mkdir: graft in as empty directory, not as copy from iso
bit1= do not report copied files
bit2= -follow, -not_*: this is not a command parameter
??? <<< bit3= use offset and cut_size for cut_out_node
>>> bit3= use offset and cut_size for -paste_in
bit4= return 3 on rejection by exclusion or user
bit5= if directory then do not add sub tree
bit6= this is a copy action: do not fake times and ownership
@ -3144,7 +3121,8 @@ ex:
3 = rejected
*/
int Xorriso_restore(struct XorrisO *xorriso,
char *img_path, char *disk_path, int flag)
char *img_path, char *disk_path,
off_t offset, off_t bytes, int flag)
{
IsoImage *volume;
char path[SfileadrL], *apt, *npt, sfe[5*SfileadrL];
@ -3223,31 +3201,17 @@ int Xorriso_restore(struct XorrisO *xorriso,
source_is_dir= (is_dir || (flag&1) || !done);
source_is_split= done && leaf_is_split;
#ifdef NIX
if((flag&8) && done) {
/* >>> handle softlinks */;
/* ??? move down from Xorriso_paste_in() :
check whether target does not exist or both are regular */;
stbuf_ret= stat(path, &target_stbuf);
if(stbuf_ret!=-1) {
target_is_dir= S_ISDIR(target_stbuf.st_mode);
if(!(target_is_dir && (source_is_dir && !source_is_split))) {
ret= Xorriso_restore_overwrite(xorriso, node, img_path, path, disk_path,
&target_stbuf, flag&16);
if(ret<=0 || ret==3)
goto ex;
stbuf_ret= -1; /* now it is removed (or can be handled properly) */
}
}
#else /* NIX */
ret= Xorriso_handle_collision(xorriso, node, img_path, path, disk_path,
} else {
ret= Xorriso_handle_collision(xorriso, node, img_path, path, disk_path,
&stbuf_ret, (source_is_dir && !source_is_split));
if(ret<=0 || ret==3)
goto ex;
#endif /* ! NIX */
if(ret<=0 || ret==3)
goto ex;
}
new_dir_made= 0;
if(stbuf_ret==-1 && (source_is_dir && !source_is_split)) {
@ -3294,7 +3258,7 @@ attach_source:;
}
} else {
ret= Xorriso_restore_disk_object(xorriso, img_path, node, path,
flag & (2|4|64));
offset, bytes, (flag & (2|4|64)) | !!(flag&8));
if(ret<=0)
goto ex;
}
@ -3313,6 +3277,55 @@ ex:;
}
/* @param flag bit0= -follow, -not: disk_path is not a command parameter
*/
int Xorriso_paste_in(struct XorrisO *xorriso, char *disk_path,
off_t startbyte, off_t bytecount, char *iso_rr_path, int flag)
{
int ret;
char eff_source[SfileadrL], eff_dest[SfileadrL], sfe[SfileadrL*5];
struct stat stbuf;
IsoNode *node;
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_dest,
2|4);
if(ret<=0)
return(ret);
ret= Xorriso_path_is_excluded(xorriso, disk_path, !(flag&1));
if(ret!=0)
return(0);
ret= stat(eff_dest, &stbuf);
if(ret!=-1 && !S_ISREG(stbuf.st_mode)) {
Xorriso_msgs_submit(xorriso, 0, eff_dest, 0, "ERRFILE", 0);
sprintf(xorriso->info_text,
"-paste_in: DISK file %s exists and is not a data file",
Text_shellsafe(eff_source, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
return(0);
}
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, iso_rr_path,
eff_source, 2);
if(ret<=0)
return(ret);
ret= Xorriso_fake_stbuf(xorriso, eff_source, &stbuf, &node, 0);
if(ret<=0)
return(0);
if(!S_ISREG(stbuf.st_mode)) {
Xorriso_msgs_submit(xorriso, 0, eff_dest, 0, "ERRFILE", 0);
sprintf(xorriso->info_text, "-paste_in: ISO file %s is not a data file",
Text_shellsafe(eff_source, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
return(0);
}
/* >>> eventually obtain parameters from file name */;
ret= Xorriso_restore(xorriso, eff_source, eff_dest, startbyte, bytecount, 8);
return(ret);
}
int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
{
int ret, error_code= 0, os_errno= 0, count= 0, pass, imgid, tunneled;