Prevented some interesting pitfalls with -mv

This commit is contained in:
Thomas Schmitt 2007-10-28 12:54:22 +00:00
parent c77e00f9f5
commit 9e50ac35da
3 changed files with 93 additions and 32 deletions

View File

@ -2188,10 +2188,18 @@ int Xorriso_info(struct XorrisO *xorriso, int flag)
*/
{
int ret;
static int note_sev= 0;
if(flag&2)
if(xorriso->request_to_abort)
return(1);
if(note_sev==0)
Xorriso__text_to_sev("NOTE", &note_sev, 0);
if(note_sev<xorriso->report_about_severity &&
note_sev<xorriso->abort_on_severity)
return(1);
if(flag&1) {
ret= Xorriso_pager(xorriso,xorriso->info_text,2);
if(ret<=0)
@ -2953,13 +2961,21 @@ ex:
}
int Xorriso__end_idx(int argc, char **argv, int idx, int flag)
int Xorriso_end_idx(struct XorrisO *xorriso,
int argc, char **argv, int idx, int flag)
{
int i;
int i, warned= 0;
for(i= idx; i<argc; i++)
for(i= idx; i<argc; i++) {
if(strcmp(argv[i], "--")==0)
break;
if((strchr(argv[i],'*')!=NULL || strchr(argv[i],'?')!=NULL) && !warned) {
sprintf(xorriso->info_text,
"Xorriso does not support address wildcards '*' and '?'");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
warned= 1;
}
}
return(i);
}
@ -3106,7 +3122,7 @@ int Xorriso_option_add(struct XorrisO *xorriso, int argc, char **argv,
int i, end_idx, ret;
char target[SfileadrL], source[SfileadrL], *ept, eff_path[SfileadrL];
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
for(i= *idx; i<end_idx; i++) {
if(Sfile_str(target,argv[i],0)<=0)
@ -3161,7 +3177,7 @@ int Xorriso_option_alter_date(struct XorrisO *xorriso,
{
int i, end_idx;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> XORRISO : decode timestring %s\n", timestring);
fprintf(stderr, ">>> LIBISOFS : -alter_date %s %s ",
@ -3367,7 +3383,7 @@ int Xorriso_option_chgrpi(struct XorrisO *xorriso, char *gid, char *path,
{
int i, end_idx;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chgrpi %s %s ", gid, path);
for(i= *idx; i<end_idx; i++)
@ -3385,7 +3401,7 @@ int Xorriso_option_chmodi(struct XorrisO *xorriso, char *mode, char *path,
{
int i, end_idx;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chmodi %s %s ", mode, path);
for(i= *idx; i<end_idx; i++)
@ -3403,7 +3419,7 @@ int Xorriso_option_chowni(struct XorrisO *xorriso, char *uid, char *path,
{
int i, end_idx;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : would perform -chowni %s %s ", uid, path);
for(i= *idx; i<end_idx; i++)
@ -3458,7 +3474,7 @@ int Xorriso_option_cp_ri(struct XorrisO *xorriso, int argc, char **argv,
{
int i, end_idx;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : -cp_ri X: ");
for(i= *idx; i<end_idx-1; i++)
@ -4086,7 +4102,7 @@ int Xorriso_option_mkdiri(struct XorrisO *xorriso, int argc, char **argv,
{
int i, end_idx;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : -mkdiri ");
for(i= *idx; i<end_idx; i++)
@ -4103,10 +4119,11 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int i, end_idx, ret, is_dir= 0, was_failure= 0;
char sfe[4*SfileadrL], eff_origin[SfileadrL], eff_dest[SfileadrL];
char sfe[4*SfileadrL], sfe2[4*SfileadrL];
char 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(xorriso, 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);
@ -4140,7 +4157,7 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
}
/* Perform movements */
for(i= *idx; i<end_idx-1; i++) {
ret= Xorriso_normalize_img_path(xorriso, argv[i], eff_origin, 1);
ret= Xorriso_normalize_img_path(xorriso, argv[i], eff_origin, 0);
if(ret<=0)
{ret= 0; goto ex;}
if(is_dir) {
@ -4163,6 +4180,11 @@ int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
goto ex;
if(ret==0)
was_failure= 1;
else {
sprintf(xorriso->info_text, "Renamed in ISO image: %s to %s\n",
Text_shellsafe(eff_origin,sfe,0),Text_shellsafe(eff_dest,sfe2,0));
Xorriso_info(xorriso, 0);
}
}
ret= !was_failure;
ex:;
@ -4469,7 +4491,7 @@ int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv,
int i, end_idx, ret;
char path[SfileadrL], eff_path[SfileadrL];
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
for(i= *idx; i<end_idx; i++) {
if(Sfile_str(path,argv[i],0)<=0)
@ -4504,7 +4526,7 @@ int Xorriso_option_rmdiri(struct XorrisO *xorriso, int argc, char **argv,
{
int i, end_idx;
end_idx= Xorriso__end_idx(argc, argv, *idx, 0);
end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
fprintf(stderr, ">>> LIBISOFS : -rmdiri ");
for(i= *idx; i<end_idx; i++)

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.27.230512"
#define Xorriso_timestamP "2007.10.28.125501"

View File

@ -445,6 +445,10 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
struct iso_tree_node *node= NULL;
char path[SfileadrL], *apt, *npt, sfe[4*SfileadrL], *cpt;
eff_path[0]= 0;
if(img_path[0]==0)
return(2); /* root directory */
if(!(flag&2)) {
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
@ -463,7 +467,6 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
if(Sfile_str(path, img_path, 0)<=0)
return(-1);
apt= npt= path;
eff_path[0]= 0;
if(path[0]!='/') {
sprintf(xorriso->info_text,
@ -471,7 +474,8 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0);
return(-1);
}
} else if(path[1]==0)
return(2); /* root directory */
for(npt= apt; !done; apt= npt+1) {
npt= strchr(apt, '/');
@ -1259,7 +1263,6 @@ int Xorriso_ls(struct XorrisO *xorriso, int flag)
static char months[12][4]= { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
rpt= xorriso->result_line;
ret= Xorriso_get_volume(xorriso, &volume, 0);
@ -1394,28 +1397,58 @@ ex:;
int Xorriso_rename(struct XorrisO *xorriso,
char origin[], char dest[], int flag)
{
int ret;
int ret, ol, dest_ret;
char sfe[4*SfileadrL], eff_dest[SfileadrL], dir_adr[SfileadrL], *cpt;
char *leafname;
char *leafname, eff_origin[SfileadrL], sfe2[4*SfileadrL];
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)
ret= Xorriso_normalize_img_path(xorriso, origin, eff_origin, 0);
if(ret<=0)
return(ret);
if(ret==2) {
dest_ret= Xorriso_normalize_img_path(xorriso, dest, eff_dest, 1);
if(dest_ret<0)
return(dest_ret);
if(dest_ret==0) { /* obtain eff_dest address despite it does not exist */
ret= Xorriso_normalize_img_path(xorriso, dest, eff_dest, 2);
if(ret<=0)
return(ret);
}
/* Prevent that destination is a subordinate of origin
(that would be a black hole plopping out of the universe) */
ol= strlen(eff_origin);
if(ol==0) {
sprintf(xorriso->info_text, "May not rename root directory");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else if(strcmp(eff_origin, eff_dest)==0) {
sprintf(xorriso->info_text, "Ignored attempt to rename %s to itself",
Text_shellsafe(eff_origin,sfe,0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
return(0);
} else if(strncmp(eff_origin, eff_dest, ol)==0 &&
(eff_dest[ol]==0 || eff_dest[ol]=='/')) {
sprintf(xorriso->info_text,
"May not rename %s to its own sub address %s",
Text_shellsafe(eff_origin,sfe,0), Text_shellsafe(eff_dest,sfe2,0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
/* Check whether destination exists and may be not overwriteable */
if(dest_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) {
} else if (dest_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) {
} else if(dest_ret>0) {
ret= Xorriso_rmi(xorriso, eff_dest, 0);
if(ret<=0)
return(0);
@ -1427,9 +1460,11 @@ int Xorriso_rename(struct XorrisO *xorriso,
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);
if(dir_adr[0]!=0) {
ret= Xorriso_graft_in(xorriso, NULL, dir_adr, 1);
if(ret<=0)
return(ret);
}
/* Move node */
ret= Xorriso_get_volume(xorriso, &volume, 0);
@ -1437,15 +1472,16 @@ int Xorriso_rename(struct XorrisO *xorriso,
return(ret);
dest_dir= (struct iso_tree_node_dir *)
iso_tree_volume_path_to_node(volume,dir_adr);
strcpy(dir_adr, origin);
strcpy(dir_adr, eff_origin);
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);
node= iso_tree_volume_path_to_node(volume,eff_origin);
if(dest_dir==NULL || origin_dir==NULL || node==NULL) {
Xorriso_process_msg_queues(xorriso,0);
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);
@ -1453,6 +1489,7 @@ int Xorriso_rename(struct XorrisO *xorriso,
}
ret= iso_tree_node_take(origin_dir, node);
if(ret==-1) {
Xorriso_process_msg_queues(xorriso,0);
sprintf(xorriso->info_text,
"Internal error on rename: failed to take node");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
@ -1465,6 +1502,8 @@ int Xorriso_rename(struct XorrisO *xorriso,
else
leafname++;
iso_tree_node_set_name(node, leafname);
Xorriso_process_msg_queues(xorriso,0);
return(1);
}