Implemented option -mv

This commit is contained in:
Thomas Schmitt 2007-10-27 22:41:24 +00:00
parent d51958fcf5
commit 47978aad19
5 changed files with 187 additions and 44 deletions

View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps .\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1) .\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "October 23, 2007" .TH XORRISO 1 "October 27, 2007"
.\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.\" Some roff macros, for reference: .\" Some roff macros, for reference:
@ -279,7 +279,7 @@ Delete the given files from the ISO image.
\fB\-rm_r\fR iso_rr_path [...] \fB\-rm_r\fR iso_rr_path [...]
Delete the given files or directory trees from the ISO image. Delete the given files or directory trees from the ISO image.
.TP .TP
> \fB\-mv\fR iso_rr_path [...] iso_rr_path \fB\-mv\fR iso_rr_path [...] iso_rr_path
Rename the given file objects in the ISO tree to the last Rename the given file objects in the ISO tree to the last
argument in the list. Use the same rules as with shell command mv. argument in the list. Use the same rules as with shell command mv.
.TP .TP

View File

@ -4102,18 +4102,67 @@ int Xorriso_option_mkdiri(struct XorrisO *xorriso, int argc, char **argv,
int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv, int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag) int *idx, int flag)
{ {
int i, end_idx; int i, end_idx, ret, is_dir= 0, was_failure= 0;
char sfe[4*SfileadrL], eff_origin[SfileadrL], eff_dest[SfileadrL];
char dest_dir[SfileadrL], *leafname;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0); end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
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;}
}
fprintf(stderr, ">>> LIBISOFS : -mvi I: "); /* Check existence of old addresses */
for(i= *idx; i<end_idx-1; i++) for(i= *idx; i<end_idx-1; i++) {
fprintf(stderr, "%s ", argv[i]); ret= Xorriso_normalize_img_path(xorriso, argv[i], eff_origin, 1);
fprintf(stderr, " -> I: %s", argv[end_idx-1]); if(ret<=0)
fprintf(stderr, "\n"); {ret= 0; goto ex;}
}
/* Evaluate target address */
ret= Xorriso_normalize_img_path(xorriso, argv[end_idx-1], eff_dest, 1);
if(ret<0)
{ret= 0; goto ex;}
if(ret==2) {
is_dir= 1;
strcpy(dest_dir, eff_dest);
} else if(end_idx - *idx > 2) {
sprintf(xorriso->info_text,
"-mvi: more than one origin given, destination is a non-directory: %s",
Text_shellsafe(argv[end_idx-1], sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;}
}
/* Perform movements */
for(i= *idx; i<end_idx-1; i++) {
ret= Xorriso_normalize_img_path(xorriso, argv[i], eff_origin, 1);
if(ret<=0)
{ret= 0; goto ex;}
if(is_dir) {
leafname= strrchr(eff_origin, '/');
if(leafname==NULL)
leafname= eff_origin;
else
leafname++;
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);
{ret= 0; goto ex;}
}
}
ret= Xorriso_rename(xorriso, eff_origin, eff_dest, 0);
if(ret<0)
goto ex;
if(ret==0)
was_failure= 1;
}
ret= !was_failure;
ex:;
(*idx)= end_idx; (*idx)= end_idx;
return(1); return(ret);
} }

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.24.175337" #define Xorriso_timestamP "2007.10.27.224148"

View File

@ -450,17 +450,22 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
return(ret); return(ret);
} }
if(img_path[0]!='/') {
strcpy(path, xorriso->wdi);
ret= Sfile_add_to_path(path, img_path, 0);
if(ret<=0)
goto much_too_long;
} else
if(Sfile_str(path, img_path, 0)<=0) if(Sfile_str(path, img_path, 0)<=0)
return(-1); return(-1);
apt= npt= path; apt= npt= path;
eff_path[0]= 0; eff_path[0]= 0;
if(path[0]==0)
return(2);
if(path[0]!='/') { if(path[0]!='/') {
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
"Unsupported relative addressing in iso_rr_path '%s'", img_path); "Internal error: Unresolvable relative addressing in iso_rr_path '%s'",
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0); img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0);
return(-1); return(-1);
} }
@ -502,6 +507,7 @@ bonked_root:;
} }
ret= Sfile_add_to_path(eff_path, apt, 0); ret= Sfile_add_to_path(eff_path, apt, 0);
if(ret<=0) { if(ret<=0) {
much_too_long:;
sprintf(xorriso->info_text, "Effective path gets much too long (%d)", sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
strlen(eff_path)+strlen(apt)+1); strlen(eff_path)+strlen(apt)+1);
if(!(flag&1)) if(!(flag&1))
@ -527,7 +533,8 @@ bonked_root:;
} }
/* @return <=0 = error , 1 = added simple node , 2 = added directory */ /** @param flag bit0= mkdir: graft in as empty directory, not as copy from disk
@return <=0 = error , 1 = added simple node , 2 = added directory */
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path, int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag) int flag)
{ {
@ -566,6 +573,7 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
path[sizeof(path)-1]= 0; path[sizeof(path)-1]= 0;
apt= npt= path; apt= npt= path;
if(!(flag&1)) {
if(lstat(disk_path, &stbuf) == -1) { if(lstat(disk_path, &stbuf) == -1) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text, sprintf(xorriso->info_text,
@ -593,6 +601,7 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
} }
} }
}
dir= iso_volume_get_root(volume); dir= iso_volume_get_root(volume);
if(dir==NULL) { if(dir==NULL) {
@ -633,7 +642,7 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
return(0); return(0);
} }
dir= (struct iso_tree_node_dir *) node; dir= (struct iso_tree_node_dir *) node;
} else if(is_dir || !done) { } else if(is_dir || (flag&1) || !done) {
dir= iso_tree_add_dir(dir, apt); dir= iso_tree_add_dir(dir, apt);
if(dir==NULL) { if(dir==NULL) {
Xorriso_process_msg_queues(xorriso,0); Xorriso_process_msg_queues(xorriso,0);
@ -649,7 +658,10 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
} }
if(done) { if(done) {
attach_source:; attach_source:;
if(is_dir) { if(flag&1) {
/* directory node was created above */;
} else if(is_dir) {
/* >>> do this by own recursive operation in order to gain /* >>> do this by own recursive operation in order to gain
full control with overwriting */; full control with overwriting */;
@ -1375,3 +1387,81 @@ ex:;
} }
int Xorriso_rename(struct XorrisO *xorriso,
char origin[], char dest[], int flag)
{
int ret;
char sfe[4*SfileadrL], eff_dest[SfileadrL], dir_adr[SfileadrL], *cpt;
char *leafname;
struct iso_volume *volume;
struct iso_tree_node_dir *origin_dir, *dest_dir;
struct iso_tree_node *node;
/* Check whether destination exists and may be not overwriteable */
ret= Xorriso_normalize_img_path(xorriso, dest, eff_dest, 1);
if(ret<0)
return(ret);
if(ret==2) {
sprintf(xorriso->info_text, "Renaming refuses to unlink directory: %s",
Text_shellsafe(eff_dest, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else if (ret==1 && !xorriso->do_overwrite) {
sprintf(xorriso->info_text, "Renaming may not overwite: %s",
Text_shellsafe(eff_dest, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else if(ret>0) {
ret= Xorriso_rmi(xorriso, eff_dest, 0);
if(ret<=0)
return(0);
}
/* Ensure existence of destination directory */
strcpy(dir_adr, eff_dest);
cpt= strrchr(dir_adr, '/');
if(cpt==NULL)
cpt= dir_adr+strlen(dir_adr);
*cpt= 0;
ret= Xorriso_graft_in(xorriso, NULL, dir_adr, 1);
if(ret<=0)
return(ret);
/* Move node */
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
dest_dir= (struct iso_tree_node_dir *)
iso_tree_volume_path_to_node(volume,dir_adr);
strcpy(dir_adr, eff_dest);
cpt= strrchr(dir_adr, '/');
if(cpt==NULL)
cpt= dir_adr+strlen(dir_adr);
*cpt= 0;
origin_dir= (struct iso_tree_node_dir *)
iso_tree_volume_path_to_node(volume,dir_adr);
node= iso_tree_volume_path_to_node(volume,origin);
if(dest_dir==NULL || origin_dir==NULL || node==NULL) {
sprintf(xorriso->info_text,
"Internal error on rename: confirmed node turns out as NULL");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
ret= iso_tree_node_take(origin_dir, node);
if(ret==-1) {
sprintf(xorriso->info_text,
"Internal error on rename: failed to take node");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
iso_tree_add_child(dest_dir, node);
leafname= strrchr(eff_dest, '/');
if(leafname==NULL)
leafname= eff_dest;
else
leafname++;
iso_tree_node_set_name(node, leafname);
return(1);
}

View File

@ -28,7 +28,8 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag);
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive, int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
int flag); int flag);
/* @return <=0 = error , 1 = added simple node , 2 = added directory /* @param flag bit0=graft in as empty directory, not as copy from disk
@return <=0 = error , 1 = added simple node , 2 = added directory
*/ */
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path, int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag); int flag);
@ -67,5 +68,8 @@ int Xorriso_ls(struct XorrisO *xorriso, int flag);
int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path, int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
char eff_path[], int flag); char eff_path[], int flag);
int Xorriso_rename(struct XorrisO *xorriso,
char origin[], char dest[], int flag);
#endif /* Xorrisoburn_includeD */ #endif /* Xorrisoburn_includeD */