Hopefully completed -cd alias -cdi
This commit is contained in:
@ -428,18 +428,137 @@ int Xorriso_get_volume(struct XorrisO *xorriso, struct iso_volume **volume,
|
||||
}
|
||||
|
||||
|
||||
/* @param eff_path returns resulting effective path.
|
||||
Must provide at least SfileadrL bytes of storage.
|
||||
@param flag bit0= do not produce problem events (unless internal error)
|
||||
@return <0 = internal error , 0 = not found ,
|
||||
1 = found simple node , 2 = found directory
|
||||
*/
|
||||
int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
|
||||
char eff_path[], int flag)
|
||||
{
|
||||
int ret, is_dir= 1, done= 0;
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_node_dir *dir= NULL;
|
||||
struct iso_tree_node *node= NULL;
|
||||
char path[SfileadrL], *apt, *npt, sfe[4*SfileadrL], *cpt;
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
|
||||
if(Sfile_str(path, img_path, 0)<=0)
|
||||
return(-1);
|
||||
apt= npt= path;
|
||||
eff_path[0]= 0;
|
||||
if(path[0]==0)
|
||||
return(2);
|
||||
|
||||
if(path[0]!='/') {
|
||||
sprintf(xorriso->info_text,
|
||||
"Unsupported relative addressing in iso_rr_path '%s'", img_path);
|
||||
if(!(flag&1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
for(npt= apt; !done; apt= npt+1) {
|
||||
npt= strchr(apt, '/');
|
||||
if(npt==NULL) {
|
||||
npt= apt+strlen(apt);
|
||||
done= 1;
|
||||
} else
|
||||
*npt= 0;
|
||||
if(*apt==0) {
|
||||
*apt= '/';
|
||||
apt++;
|
||||
if(done)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if(strcmp(apt,".")==0)
|
||||
continue;
|
||||
if(strcmp(apt,"..")==0) {
|
||||
node= (struct iso_tree_node *) dir;
|
||||
if(node==NULL) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Relative addressing in path exceeds root directory: %s",
|
||||
Text_shellsafe(path, sfe, 0));
|
||||
if(!(flag&1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
dir= iso_tree_node_get_parent(node);
|
||||
|
||||
/* truncate eff_path */;
|
||||
cpt= strrchr(eff_path, '/');
|
||||
if(cpt==NULL) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Internal error: less '/' than parent directories in %s",
|
||||
Text_shellsafe(img_path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
||||
return(-1);
|
||||
}
|
||||
*cpt= 0;
|
||||
continue;
|
||||
}
|
||||
ret= Sfile_add_to_path(eff_path, apt, 0);
|
||||
if(ret<=0) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Effective path in ISO image gets much too long (%d)",
|
||||
strlen(eff_path)+strlen(apt)+1);
|
||||
if(!(flag&1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
dir= (struct iso_tree_node_dir *) node;
|
||||
node= iso_tree_volume_path_to_node(volume,eff_path);
|
||||
if(node==NULL) {
|
||||
sprintf(xorriso->info_text, "Cannot find in ISO image: %s",
|
||||
Text_shellsafe(eff_path, sfe, 0));
|
||||
if(!(flag&1))
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
if(dir==NULL) /* could be false with "/dir/.." */
|
||||
dir= iso_tree_node_get_parent(node);
|
||||
is_dir= LIBISO_ISDIR(node);
|
||||
}
|
||||
return(1+!!is_dir);
|
||||
}
|
||||
|
||||
|
||||
/* @return <=0 = error , 1 = added simple node , 2 = added directory */
|
||||
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
|
||||
int flag)
|
||||
{
|
||||
struct iso_volume *volume;
|
||||
struct iso_tree_radd_dir_behavior behav= {NULL, 0, 0};
|
||||
char path[SfileadrL], *apt, *npt;
|
||||
char path[SfileadrL], *apt, *npt, *cpt;
|
||||
struct iso_tree_node_dir *dir;
|
||||
struct iso_tree_node *node;
|
||||
int done= 0, is_dir= 0, l, ret;
|
||||
struct stat stbuf;
|
||||
|
||||
for(cpt= img_path; 1; cpt++) {
|
||||
if(cpt[0]!='/')
|
||||
break;
|
||||
cpt= strstr(cpt,"/.");
|
||||
if(cpt==NULL)
|
||||
break;
|
||||
if(cpt[2]=='.') {
|
||||
if(cpt[3]=='/' || cpt[3]==0)
|
||||
break;
|
||||
} else if(cpt[2]=='/' || cpt[2]==0)
|
||||
break;
|
||||
}
|
||||
if(cpt!=NULL) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Unsupported relative addressing in iso_rr_path '%s'", img_path);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
|
Reference in New Issue
Block a user