Implemented option -cpr

This commit is contained in:
Thomas Schmitt 2007-12-25 16:02:06 +00:00
parent ee188aa38a
commit 4f759abb80
4 changed files with 166 additions and 64 deletions

View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "December 22, 2007"
.TH XORRISO 1 "December 25, 2007"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -491,11 +491,19 @@ The resulting words are used as both, iso_rr_path and disk path. Eventually
Like -add but read the parameter words from file disk_path.
One pathspec resp. disk_path pattern per line.
.TP
> \fB\-cp_r\fR disk_path [***] iso_rr_path
\fB\-cpr\fR disk_path [***] iso_rr_path
Insert the given files or directory trees from filesystem
into the ISO image.
Use the same rules for generating the ISO addresses as
would be done with shell command cp -r.
.br
The rules for generating the ISO addresses are similar as with
shell command cp -r. Nevertheless, directories of the iso_rr_path
are created if necessary. Especially a not yet existing iso_rr_path
will be handled as directory if multiple disk_paths are present.
The leafnames of the multiple disk_paths will be grafted under that
directory as would be done with an existing directory.
.br
If a single disk_path is present then a non-existing iso_rr_path will
have the same type as the disk_path.
.TP
\fB\-rm\fR iso_rr_path [***]
Delete the given files from the ISO image.

View File

@ -195,6 +195,27 @@ int Sfile_component_pointer(char *path, char **sourcept, int idx, int flag)
}
int Sfile_leafname(char *path, char leafname[SfileadrL], int flag)
{
int count, ret;
char *lpt;
leafname[0]= 0;
count= Sfile_count_components(path, 0);
if(count==0)
return(0);
ret= Sfile_component_pointer(path, &lpt, count-1, 0);
if(ret<=0)
return(ret);
if(Sfile_str(leafname, lpt, 0)<=0)
return(0);
lpt= strchr(leafname, '/');
if(lpt!=NULL)
*lpt= 0;
return(1);
}
int Sfile_add_to_path(char path[SfileadrL], char *addon, int flag)
{
int l;
@ -5393,6 +5414,71 @@ ex:;
Dirseq_destroy(&dirseq, 0);
return(ret);
}
/* @param flag bit0= a non-existing target of multiple sources is a directory
bit1= these are disk_paths
@return <=0 iis error, 1= leaf file object, 2= directory
*/
int Xorriso_cpmv_args(struct XorrisO *xorriso, char *cmd,
int argc, char **argv, int *idx,
int *optc, char ***optv, char eff_dest[SfileadrL],
int flag)
{
int destc= 0, is_dir=0, end_idx, nflag, ret;
char **destv= NULL, *wd;
char sfe[5*SfileadrL];
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx,
(xorriso->do_iso_rr_pattern==1)|(flag&2));
if(end_idx - *idx < 2) {
sprintf(xorriso->info_text, "%s: not enough arguments", cmd);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;}
}
ret= Xorriso_opt_args(xorriso, argc, argv, *idx, &end_idx, optc, optv,
16); /* ignore last argument */
if(ret<=0)
goto ex;
ret= Xorriso_opt_args(xorriso, argc, argv, end_idx, &end_idx, &destc, &destv,
32|64); /* demand one match, or 0 with a constant */
if(ret<=0)
goto ex;
/* Evaluate target address */
if(flag&2) {
wd= xorriso->wdx;
nflag= 1|2|4;
} else {
wd= xorriso->wdi;
nflag= 1;
}
ret= Xorriso_normalize_img_path(xorriso, wd, destv[0], eff_dest, nflag);
if(ret<0)
{ret= 0; goto ex;}
if(ret==2 || ((flag&1) && *optc > 1 && ret==0)) {
is_dir= 1;
} else if(*optc > 1) {
sprintf(xorriso->info_text,
"%s: more than one origin given, destination is a non-directory: %s",
cmd, Text_shellsafe(destv[0], sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;}
}
if(ret==0) { /* compute complete eff_dest */
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, destv[0],eff_dest,2);
if(ret<0)
{ret= 0; goto ex;}
}
ret= 1+is_dir;
ex:;
Xorriso_opt_args(xorriso, argc, argv, *idx, &end_idx, &destc, &destv, 256);
(*idx)= end_idx;
return(ret);
}
/* ---------------------------- Options API ------------------------ */
@ -5971,22 +6057,61 @@ int Xorriso_option_commit(struct XorrisO *xorriso, int flag)
}
/* Option -cp_r alias -cp_ri */
int Xorriso_option_cp_ri(struct XorrisO *xorriso, int argc, char **argv,
/* Option -cpr alias -cpri */
int Xorriso_option_cpri(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int i, end_idx;
int i, ret, is_dir= 0, was_failure= 0, fret;
char eff_origin[SfileadrL], eff_dest[SfileadrL];
char dest_dir[SfileadrL], leafname[SfileadrL];
int optc= 0;
char **optv= NULL;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : -cp_ri X: ");
for(i= *idx; i<end_idx-1; i++)
fprintf(stderr, "%s ", argv[i]);
fprintf(stderr, " -> I: %s", argv[end_idx-1]);
fprintf(stderr, "\n");
(*idx)= end_idx;
return(1);
ret= Xorriso_cpmv_args(xorriso, "-cpri", argc, argv, idx,
&optc, &optv, eff_dest, 1);
if(ret<=0)
goto ex;
if(ret==2) {
is_dir= 1;
strcpy(dest_dir, eff_dest);
}
/* Perform graft-ins */
for(i= 0; i<optc && !xorriso->request_to_abort; i++) {
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, optv[i], eff_origin,
2|4);
if(ret<=0 || xorriso->request_to_abort)
goto problem_handler;
if(is_dir) {
ret= Sfile_leafname(eff_origin, leafname, 0);
if(ret<=0)
goto problem_handler;
strcpy(eff_dest, dest_dir);
ret= Sfile_add_to_path(eff_dest, leafname, 0);
if(ret<=0) {
printf(xorriso->info_text, "Effective path gets much too long (%d)",
strlen(eff_dest)+strlen(leafname)+1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
goto problem_handler;
}
}
ret= Xorriso_graft_in(xorriso, eff_origin, eff_dest, 0);
if(ret<=0 || xorriso->request_to_abort)
goto problem_handler;
sprintf(xorriso->info_text, "Added to ISO image: %s '%s'='%s'\n",
(ret>1 ? "directory" : "file"), eff_dest, eff_origin);
if(!(flag&1))
Xorriso_info(xorriso, 0);
continue; /* regular bottom of loop */
problem_handler:;
was_failure= 1;
fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
if(fret>=0)
continue;
goto ex;
}
ret= !was_failure;
ex:;
return(ret);
}
@ -6420,7 +6545,7 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" iso_rr_path=disk_path . Only \"off\" allows eventual",
" -disk_pattern expansion.",
"",
"> -cp_r disk_path [...] iso_rr_path",
"> -cpr disk_path [...] iso_rr_path",
" Insert the given files or directory trees from filesystem",
" into the ISO image.",
" -rm iso_rr_path [***]",
@ -6869,46 +6994,18 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
{
int i, end_idx, ret, is_dir= 0, was_failure= 0, fret;
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
char eff_origin[SfileadrL], eff_dest[SfileadrL];
char dest_dir[SfileadrL], *leafname;
int optc= 0,destc= 0;
char **optv= NULL, **destv= NULL;
char eff_origin[SfileadrL], eff_dest[SfileadrL], dest_dir[SfileadrL];
char *leafname;
int optc= 0;
char **optv= NULL;
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx,
xorriso->do_iso_rr_pattern==1);
if(end_idx - *idx < 2) {
sprintf(xorriso->info_text, "-mvi: not enough arguments");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;}
}
ret= Xorriso_opt_args(xorriso, argc, argv, *idx, &end_idx, &optc, &optv,
16); /* ignore last argument */
ret= Xorriso_cpmv_args(xorriso, "-mvi", argc, argv, idx,
&optc, &optv, eff_dest, 0);
if(ret<=0)
goto ex;
ret= Xorriso_opt_args(xorriso, argc, argv, end_idx, &end_idx, &destc, &destv,
32|64); /* demand one match, or 0 with a constant */
if(ret<=0)
goto ex;
/* Evaluate target address */
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, destv[0], eff_dest, 1);
if(ret<0)
{ret= 0; goto ex;}
if(ret==2) {
is_dir= 1;
strcpy(dest_dir, eff_dest);
} else if(optc > 2) {
sprintf(xorriso->info_text,
"-mvi: more than one origin given, destination is a non-directory: %s",
Text_shellsafe(destv[0], sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;}
}
if(ret==0) { /* compute complete eff_dest */
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, destv[0],eff_dest,2);
if(ret<0)
{ret= 0; goto ex;}
}
/* Perform movements */
for(i= 0; i<optc; i++) {
@ -6916,11 +7013,9 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
if(ret<=0 || xorriso->request_to_abort)
goto problem_handler;
if(is_dir) {
leafname= strrchr(eff_origin, '/');
if(leafname==NULL)
leafname= eff_origin;
else
leafname++;
ret= Sfile_leafname(eff_origin, leafname, 0);
if(ret<=0)
goto problem_handler;
strcpy(eff_dest, dest_dir);
ret= Sfile_add_to_path(eff_dest, leafname, 0);
if(ret<=0) {
@ -6947,9 +7042,8 @@ problem_handler:;
}
ret= !was_failure;
ex:;
(*idx)= end_idx;
Xorriso_opt_args(xorriso, argc, argv, *idx, &end_idx, &optc, &optv, 256);
Xorriso_opt_args(xorriso, argc, argv, *idx, &end_idx, &destc, &destv, 256);
(*idx)= end_idx;
return(ret);
}
@ -7675,8 +7769,8 @@ next_command:;
} else if(strcmp(cmd,"commit")==0) {
ret= Xorriso_option_commit(xorriso, 0);
} else if(strcmp(cmd,"cp_r")==0 || strcmp(cmd,"-cp_ri")==0) {
ret= Xorriso_option_cp_ri(xorriso, argc, argv, idx, 0);
} else if(strcmp(cmd,"cpr")==0 || strcmp(cmd,"-cpri")==0) {
ret= Xorriso_option_cpri(xorriso, argc, argv, idx, 0);
} else if(strcmp(cmd,"cut_out")==0) {
(*idx)+= 2;

View File

@ -167,8 +167,8 @@ int Xorriso_option_close(struct XorrisO *xorriso, char *mode, int flag);
/* @param flag bit0= do not aquire outdrive as new indrive */
int Xorriso_option_commit(struct XorrisO *xorriso, int flag);
/* Option -cp_r alias -cp_ri */
int Xorriso_option_cp_ri( struct XorrisO *xorriso, int argc, char **argv,
/* Option -cpr alias -cpri */
int Xorriso_option_cpri( struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag);
/* Option -cut_out */

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.12.24.161107"
#define Xorriso_timestamP "2007.12.25.160100"