Hopefully completed -cdx

This commit is contained in:
Thomas Schmitt 2007-10-21 18:52:03 +00:00
parent 9ee5534c29
commit 71c44d8a86
5 changed files with 68 additions and 80 deletions

View File

@ -523,11 +523,11 @@ foreseeable consumption by next -commit.)
.TP .TP
.B Navigation in ISO image and disk filesystem: .B Navigation in ISO image and disk filesystem:
.TP .TP
> \fB\-cd\fR iso_rr_path \fB\-cd\fR iso_rr_path
Change the current working directory in the emerging ISO Change the current working directory in the emerging ISO
image as it is at the moment. image as it is at the moment.
.TP .TP
> \fB\-cdx\fR disk_path \fB\-cdx\fR disk_path
Change the current working directory on filesystem. Change the current working directory on filesystem.
.TP .TP
\fB\-pwd\fR \fB\-pwd\fR

View File

@ -3262,7 +3262,7 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
strcpy(xorriso->wdi,""); strcpy(xorriso->wdi,"");
Xorriso_option_pwdi(xorriso, 0); Xorriso_option_pwdi(xorriso, 0);
return(1); return(1);
} if(iso_rr_path[0]!='/') { } else if(iso_rr_path[0]!='/') {
strcpy(path, xorriso->wdi); strcpy(path, xorriso->wdi);
if(Sfile_add_to_path(path,iso_rr_path,0)<=0) if(Sfile_add_to_path(path,iso_rr_path,0)<=0)
return(-1); return(-1);
@ -3271,37 +3271,16 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
return(-1); return(-1);
} }
#ifdef NIX
int l;
if(Sfile_str(xorriso->wdi,path,0)<=0)
return(-1);
ret= Xorriso_ls(xorriso, 2); /* check existence */
if(ret<=0) {
sprintf(xorriso->info_text,
"-cdi: not found or not a directory : %s",
Text_shellsafe(iso_rr_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
l= strlen(xorriso->wdi);
while(l>0)
if(xorriso->wdi[l-1]=='/')
xorriso->wdi[--l]= 0;
else
break;
#else
ret= Xorriso_normalize_img_path(xorriso, path, eff_path, 0); ret= Xorriso_normalize_img_path(xorriso, path, eff_path, 0);
if(ret<=0) if(ret<=0)
return(ret); return(ret);
if(ret!=2) { if(ret!=2) {
sprintf(xorriso->info_text, "-cdi: not a directory : %s", sprintf(xorriso->info_text, "-cdi: not a directory : %s",
Text_shellsafe(iso_rr_path, sfe, 0)); Text_shellsafe(eff_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0); return(0);
} }
strcpy(xorriso->wdi, eff_path); strcpy(xorriso->wdi, eff_path);
#endif
Xorriso_option_pwdi(xorriso, 0); Xorriso_option_pwdi(xorriso, 0);
return(1); return(1);
@ -3311,8 +3290,8 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
/* Option -cdx */ /* Option -cdx */
int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag) int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
{ {
char sfe[4*SfileadrL]; char sfe[4*SfileadrL], path[SfileadrL], eff_path[SfileadrL];;
int ret, l; int ret;
if (strlen(disk_path)>sizeof(xorriso->wdx)) { if (strlen(disk_path)>sizeof(xorriso->wdx)) {
sprintf(xorriso->info_text,"-cdx: disk_path too long (%d > %d)", sprintf(xorriso->info_text,"-cdx: disk_path too long (%d > %d)",
@ -3328,29 +3307,36 @@ int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
strcpy(xorriso->wdx,""); strcpy(xorriso->wdx,"");
Xorriso_option_pwdx(xorriso, 0); Xorriso_option_pwdx(xorriso, 0);
return(1); return(1);
} else if(disk_path[0]!='/') {
strcpy(path, xorriso->wdi);
if(Sfile_add_to_path(path,disk_path,0)<=0)
return(-1);
} else {
if(Sfile_str(path,disk_path,0)<=0)
return(-1);
} }
ret= 1; ret= Xorriso_normalize_img_path(xorriso, path, eff_path, 2);
ret= Sfile_type(disk_path,1|4|8); if(ret<=0)
if(ret<0) { return(ret);
sprintf(xorriso->info_text,"-cdx: file not found :\n%s",disk_path); if(eff_path[0]) {
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); ret= Sfile_type(eff_path,1|4|8);
return(0); if(ret<0) {
sprintf(xorriso->info_text,"-cdx: file not found : %s",
Text_shellsafe(eff_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(ret!=2) {
sprintf(xorriso->info_text,
"-cdx: not a directory : %s",
Text_shellsafe(eff_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
} }
if(ret!=2) { if(Sfile_str(xorriso->wdx,eff_path,0)<=0)
sprintf(xorriso->info_text,
"-cdx: file is not a directory :\n%s",disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(Sfile_str(xorriso->wdx,disk_path,0)<=0)
return(-1); return(-1);
l= strlen(xorriso->wdx);
while(l>0)
if(xorriso->wdx[l-1]=='/')
xorriso->wdx[--l]= 0;
else
break;
Xorriso_option_pwdx(xorriso, 0); Xorriso_option_pwdx(xorriso, 0);
return(1); return(1);
} }

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.21.151124" #define Xorriso_timestamP "2007.10.21.185248"

View File

@ -431,6 +431,7 @@ int Xorriso_get_volume(struct XorrisO *xorriso, struct iso_volume **volume,
/* @param eff_path returns resulting effective path. /* @param eff_path returns resulting effective path.
Must provide at least SfileadrL bytes of storage. Must provide at least SfileadrL bytes of storage.
@param flag bit0= do not produce problem events (unless internal error) @param flag bit0= do not produce problem events (unless internal error)
bit1= work purely literally, do not use libisofs
@return <0 = internal error , 0 = not found , @return <0 = internal error , 0 = not found ,
1 = found simple node , 2 = found directory 1 = found simple node , 2 = found directory
*/ */
@ -443,9 +444,11 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
struct iso_tree_node *node= NULL; struct iso_tree_node *node= NULL;
char path[SfileadrL], *apt, *npt, sfe[4*SfileadrL], *cpt; char path[SfileadrL], *apt, *npt, sfe[4*SfileadrL], *cpt;
ret= Xorriso_get_volume(xorriso, &volume, 0); if(!(flag&2)) {
if(ret<=0) ret= Xorriso_get_volume(xorriso, &volume, 0);
return(ret); if(ret<=0)
return(ret);
}
if(Sfile_str(path, img_path, 0)<=0) if(Sfile_str(path, img_path, 0)<=0)
return(-1); return(-1);
@ -479,50 +482,48 @@ int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *img_path,
if(strcmp(apt,".")==0) if(strcmp(apt,".")==0)
continue; continue;
if(strcmp(apt,"..")==0) { if(strcmp(apt,"..")==0) {
node= (struct iso_tree_node *) dir; if(!(flag&2)) {
if(node==NULL) { node= (struct iso_tree_node *) dir;
sprintf(xorriso->info_text, if(node==NULL) {
"Relative addressing in path exceeds root directory: %s", bonked_root:;
Text_shellsafe(path, sfe, 0)); sprintf(xorriso->info_text,
if(!(flag&1)) "Relative addressing in path exceeds root directory: %s",
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Text_shellsafe(path, sfe, 0));
return(0); if(!(flag&1))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
dir= iso_tree_node_get_parent(node);
} }
dir= iso_tree_node_get_parent(node);
/* truncate eff_path */; /* truncate eff_path */;
cpt= strrchr(eff_path, '/'); cpt= strrchr(eff_path, '/');
if(cpt==NULL) { if(cpt==NULL) /* ??? if not flag&2 then this is a bug */
sprintf(xorriso->info_text, goto bonked_root;
"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; *cpt= 0;
continue; continue;
} }
ret= Sfile_add_to_path(eff_path, apt, 0); ret= Sfile_add_to_path(eff_path, apt, 0);
if(ret<=0) { if(ret<=0) {
sprintf(xorriso->info_text, sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
"Effective path in ISO image gets much too long (%d)",
strlen(eff_path)+strlen(apt)+1); strlen(eff_path)+strlen(apt)+1);
if(!(flag&1)) if(!(flag&1))
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0); return(0);
} }
dir= (struct iso_tree_node_dir *) node; if(!(flag&2)) {
node= iso_tree_volume_path_to_node(volume,eff_path); dir= (struct iso_tree_node_dir *) node;
if(node==NULL) { node= iso_tree_volume_path_to_node(volume,eff_path);
sprintf(xorriso->info_text, "Cannot find in ISO image: %s", if(node==NULL) {
Text_shellsafe(eff_path, sfe, 0)); sprintf(xorriso->info_text, "Cannot find in ISO image: %s",
if(!(flag&1)) Text_shellsafe(eff_path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0); if(!(flag&1))
return(0); 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);
} }
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(1+!!is_dir);
} }

View File

@ -58,6 +58,7 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag);
int Xorriso_ls(struct XorrisO *xorriso, int flag); int Xorriso_ls(struct XorrisO *xorriso, int flag);
/* @param flag bit0= do not produce problem events (unless internal error) /* @param flag bit0= do not produce problem events (unless internal error)
bit1= work purely literally, do not use libisofs
@return <0 = internal error , 0 = not found , @return <0 = internal error , 0 = not found ,
1 = found simple node , 2 = found directory 1 = found simple node , 2 = found directory
*/ */