Began to implement -ls and -ls_l, enhanced -cdi, not done yet

This commit is contained in:
Thomas Schmitt 2007-10-21 12:42:27 +00:00
parent 7f9694b2b4
commit 46a56ad8d0
4 changed files with 150 additions and 21 deletions

View File

@ -3243,7 +3243,7 @@ int Xorriso_option_blank(struct XorrisO *xorriso, char *mode, int flag)
/* Option -cd alias -cdi */
int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
{
char sfe[4*SfileadrL];
char sfe[4*SfileadrL], path[SfileadrL];
int ret, l;
if (strlen(iso_rr_path)>sizeof(xorriso->wdi)) {
@ -3260,18 +3260,25 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
strcpy(xorriso->wdi,"");
Xorriso_option_pwdi(xorriso, 0);
return(1);
} if(iso_rr_path[0]!='/') {
strcpy(path, xorriso->wdi);
if(Sfile_add_to_path(path,iso_rr_path,0)<=0)
return(-1);
} else {
if(Sfile_str(path,iso_rr_path,0)<=0)
return(-1);
}
ret= 1;
/* >>> LIBISOFS: check whether directory exists in ISO image */;
ret= Xorriso_ls(xorriso, 2); /* check existence */
if(ret<=0) {
sprintf(xorriso->info_text,
"-cdi: not found or not a directory :\n%s",iso_rr_path);
"-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);
}
if(Sfile_str(xorriso->wdi,iso_rr_path,0)<=0)
if(Sfile_str(xorriso->wdi,path,0)<=0)
return(-1);
l= strlen(xorriso->wdi);
while(l>0)
@ -3963,15 +3970,15 @@ int Xorriso_option_j_capital(struct XorrisO *xorriso, int flag)
/* @param flag bit0= long format (-ls_l) */
int Xorriso_option_lsi(struct XorrisO *xorriso, char *pattern, int flag)
{
char sfe[4*SfileadrL];
int ret;
if(strcmp(pattern,"*")!=0 && pattern[0])
fprintf(stderr, ">>> XORRISO : TODO : filter by pattern %s\n", pattern);
fprintf(stderr, ">>> XORRISO : filter by pattern %s\n", pattern);
/* >>> prepare regex */
fprintf(stderr, ">>> LIBISOFS : -ls of ISO directory %s\n",
Text_shellsafe(xorriso->wdi, sfe, 0));
return(1);
ret= Xorriso_ls(xorriso, flag&1);
return(ret);
}

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.21.105228"
#define Xorriso_timestamP "2007.10.21.124315"

View File

@ -989,8 +989,28 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag)
}
int Xorriso_node_from_path(struct XorrisO *xorriso, struct iso_volume *volume,
char *path, struct iso_tree_node **node, int flag)
{
char sfe[4*SfileadrL];
*node= iso_tree_volume_path_to_node(volume, path);
Xorriso_process_msg_queues(xorriso,0);
if(*node==NULL) {
sprintf(xorriso->info_text, "Cannot find path %s in loaded ISO image",
Text_shellsafe(path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
return(1);
}
/* @param flag bit0= remove whole sub tree: rm -r
bit1=remove empty directory: rmdir
@return <=0 = error
1 = removed simple node
2 = removed directory or tree
*/
int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
{
@ -1010,14 +1030,9 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
victim_node= iso_tree_volume_path_to_node(volume, path);
Xorriso_process_msg_queues(xorriso,0);
if(victim_node==NULL) {
sprintf(xorriso->info_text, "Cannot find path %s in loaded ISO image",
Text_shellsafe(path, sfe, 0));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
ret= Xorriso_node_from_path(xorriso, volume, path, &victim_node, 0);
if(ret<=0)
return(ret);
if(LIBISO_ISDIR(victim_node))
is_dir= 1;
@ -1074,4 +1089,108 @@ int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag)
}
/* @param flag bit0= long format , bit1= only check for directory existence */
int Xorriso_ls(struct XorrisO *xorriso, int flag)
{
int ret, is_dir= 0;
struct iso_tree_node *node;
struct iso_tree_node_dir *dir_node;
struct iso_volume *volume;
struct iso_tree_iter *iter;
char sfe[4*SfileadrL], *npt, *rpt, perms[10];
mode_t st_mode;
rpt= xorriso->result_line;
ret= Xorriso_get_volume(xorriso, &volume, 0);
if(ret<=0)
return(ret);
ret= Xorriso_node_from_path(xorriso, volume, xorriso->wdi, &node, 0);
if(ret<=0)
goto wdi_is_not_a_dir;
if(LIBISO_ISDIR(node))
is_dir= 1;
if(!is_dir) {
wdi_is_not_a_dir:;
sprintf(xorriso->info_text,
"Working directory path does not lead to a directory in ISO image");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(flag&2)
return(1);
dir_node= (struct iso_tree_node_dir *) node;
iter= iso_tree_node_children(dir_node);
Xorriso_process_msg_queues(xorriso,0);
/* ??? >>> is the iteration sorted by name ? */
/* if not: >>> copy to char * array */
while((node= iso_tree_iter_next(iter)) != NULL ) {
npt= (char *) iso_tree_node_get_name(node);
#ifdef Xorriso_with_regeX
if(xorriso->re!=NULL) {
/* >>> test with regex */;
}
#endif /* Xorriso_with_regeX */
rpt[0]= 0;
if(flag&1) {
/* >>> prepend attribute info */;
if(is_dir)
strcat(rpt, "d");
else if(LIBISO_ISREG(node))
strcat(rpt, "-");
else if(LIBISO_ISLNK(node))
strcat(rpt, "l");
else
strcat(rpt, "?");
st_mode= iso_tree_node_get_permissions(node);
strcpy(perms,"---------");
if(st_mode&S_IRUSR) perms[0]= 'r';
if(st_mode&S_IWUSR) perms[1]= 'w';
if(st_mode&S_IXUSR) perms[2]= 'x';
if(st_mode&S_IRGRP) perms[3]= 'r';
if(st_mode&S_IWGRP) perms[4]= 'w';
if(st_mode&S_IXGRP) perms[5]= 'x';
if(st_mode&S_IROTH) perms[6]= 'r';
if(st_mode&S_IWOTH) perms[7]= 'w';
if(st_mode&S_IXOTH) perms[8]= 'x';
strcat(rpt, perms);
/* >>> With directories this should be : number of subdirs + 2 */
/* >>> ??? How to obtain RR harlink number for other types ? */
strcat(rpt," 1 ");
sprintf(rpt+strlen(rpt), "%7lu ",
(unsigned long) iso_tree_node_get_uid(node));
sprintf(rpt+strlen(rpt), "%7lu ",
(unsigned long) iso_tree_node_get_gid(node));
/* >>> obtain size */
sprintf(rpt+strlen(rpt), "_no_size ");
/* >>> obtain date */
sprintf(rpt+strlen(rpt), "__no__date__ ");
}
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n",
Text_shellsafe(npt, sfe, 0));
Xorriso_result(xorriso, 0);
}
/* ??? >>> sort */
/* ??? >>> output loop */
Xorriso_process_msg_queues(xorriso,0);
return(1);
}

View File

@ -54,6 +54,9 @@ int Xorriso_format_media(struct XorrisO *xorriso, int flag);
*/
int Xorriso_rmi(struct XorrisO *xorriso, char *path, int flag);
/* @param flag bit0= long format , bit1= only check for directory existence */
int Xorriso_ls(struct XorrisO *xorriso, int flag);
#endif /* Xorrisoburn_includeD */