Suffix rollback with -set_filter --remove-all-filters

This commit is contained in:
2009-04-06 10:08:48 +00:00
parent 9192380e90
commit f99b7182f5
3 changed files with 144 additions and 11 deletions

View File

@ -9780,6 +9780,88 @@ int Xorriso_destroy_all_extf(struct XorrisO *xorriso, int flag)
}
/*
@param flag bit0= return 2 if renaming is not possible by libisofs
(always: if demanded strip suffix is missing
or if suffix makes name length > 255)
bit1= strip suffix rather than appending it
*/
int Xorriso_rename_suffix(struct XorrisO *xorriso, IsoNode *node, char *suffix,
char *show_path, int flag)
{
int ret, lo= 0, ls= 0, strip_suffix;
char *old_name= NULL, new_name[SfileadrL], *show_name;
strip_suffix= !!(flag & 2);
old_name= strdup((char *) iso_node_get_name(node));
show_name= old_name;
if(show_path != NULL)
if(show_path[0] != 0)
show_name= show_path;
lo= strlen(old_name);
ls= strlen(suffix);
if(strip_suffix) {
if(lo <= ls) {
/* refuse gracefully */
ret= 2; goto ex;
}
if(strcmp(old_name + lo - ls, suffix) != 0) {
ret= 2; goto ex;
}
if(lo > sizeof(new_name))
goto cannot_remove_suffix;
strcpy(new_name, old_name);
new_name[lo - ls]= 0;
ret = iso_node_set_name(node, new_name);
if (ret < 0) {
Xorriso_process_msg_queues(xorriso,0);
if (!(flag & 1))
Xorriso_report_iso_error(xorriso, "", ret,
"Error when renaming ISO node", 0, "FAILURE", 1);
cannot_remove_suffix:;
strcpy(xorriso->info_text, "-set_filter: Cannot remove suffix from ");
Text_shellsafe(show_name, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
(flag & 1) ? "WARNING" : "FAILURE", 0);
ret= 2 * (flag & 1); goto ex;
}
} else {
/* check whether suffix already present */
if(lo >= ls)
if(strcmp(old_name + lo - ls, suffix) == 0) {
/* refuse gracefully */
ret= 2; goto ex;
}
if(lo + ls > 255) {
cannot_append_suffix:;
strcpy(xorriso->info_text, "-set_filter: Cannot append suffix to ");
Text_shellsafe(show_name, xorriso->info_text, 1);
strcat(xorriso->info_text, ". Left unfiltered.");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
(flag & 1) ? "WARNING" : "FAILURE", 0);
ret= 2 * (flag & 1); goto ex;
}
sprintf(new_name, "%s%s", old_name, suffix);
ret = iso_node_set_name(node, new_name);
if (ret < 0) {
Xorriso_process_msg_queues(xorriso,0);
if (!(flag & 1))
Xorriso_report_iso_error(xorriso, "", ret,
"Error when renaming ISO node", 0, "FAILURE", 1);
goto cannot_append_suffix;
}
}
ret= 1;
ex:;
if(old_name != NULL)
free(old_name);
Xorriso_process_msg_queues(xorriso,0);
return(ret);
}
/*
@param flag bit0= return 2 if renaming is not possible
bit1= print pacifier messages
@ -9787,7 +9869,8 @@ int Xorriso_destroy_all_extf(struct XorrisO *xorriso, int flag)
int Xorriso_set_filter(struct XorrisO *xorriso, void *in_node,
char *path, char *filter_name, int flag)
{
int ret, lo= 0, ls= 0, strip_suffix= 0, strip_filter= 0, filter_ret;
int ret, strip_suffix= 0, strip_filter= 0, filter_ret;
int explicit_suffix= 0;
IsoNode *node;
IsoFile *file;
struct Xorriso_lsT *found_lst;
@ -9795,6 +9878,12 @@ int Xorriso_set_filter(struct XorrisO *xorriso, void *in_node,
IsoExternalFilterCommand *cmd = NULL;
char *old_name= NULL, new_name[SfileadrL], *suffix= "";
#ifndef NIX
IsoStream *stream;
#else
int lo= 0, ls= 0;
#endif
new_name[0]= 0;
node= (IsoNode *) in_node;
@ -9817,6 +9906,7 @@ int Xorriso_set_filter(struct XorrisO *xorriso, void *in_node,
if(strlen(filter_name) > 21) {
strip_suffix= (filter_name[20] != '+');
suffix= filter_name + 21;
explicit_suffix= 1;
}
} else {
ret= Xorriso_lookup_extf(xorriso, filter_name, &found_lst, 0);
@ -9835,6 +9925,18 @@ int Xorriso_set_filter(struct XorrisO *xorriso, void *in_node,
}
if(suffix[0]) {
#ifndef NIX
/* >>> would need full iso_rr_path of node for showing */;
ret= Xorriso_rename_suffix(xorriso, node, suffix, path,
(flag & 1) | (strip_suffix ? 2 : 0));
if(ret <= 0 || ret == 2)
goto ex;
#else /* ! NIX */
old_name= strdup((char *) iso_node_get_name(node));
lo= strlen(old_name);
ls= strlen(suffix);
@ -9895,10 +9997,28 @@ cannot_append_suffix:;
goto cannot_append_suffix;
}
}
#endif /* ! NIX */
}
if(strip_filter) {
while(1) {
if(!explicit_suffix) {
stream= iso_file_get_stream(file);
ret= iso_stream_get_external_filter(stream, &cmd, 0);
if(ret > 0) {
if(cmd->suffix[0]) {
/* >>> would need the current renaming state of path */;
ret= Xorriso_rename_suffix(xorriso, node, cmd->suffix, NULL,
(flag & 1) | (!(cmd->behavior & 8) << 1));
if(ret <= 0 || ret == 2)
goto ex;
}
}
}
ret= iso_file_remove_filter(file, 0);
if(ret != 1)
break;
@ -10004,6 +10124,13 @@ int Xorriso_external_filter(struct XorrisO *xorriso,
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
if((!(flag & 1)) && path[0] != '/') {
sprintf(xorriso->info_text,
"-external_filter : Given command path does not begin by '/' : ");
Text_shellsafe(path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
delete= flag & 1;
@ -10048,7 +10175,10 @@ int Xorriso_external_filter(struct XorrisO *xorriso,
*what_next= 0;
what_next++;
}
if(strncmp(what, "suffix=", 7) == 0) {
if(strncmp(what, "default", 7) == 0) {
suffix= "";
behavior= 0;
} else if(strncmp(what, "suffix=", 7) == 0) {
suffix= what + 7;
} else if(strcmp(what, "remove_suffix") == 0) {
behavior|= 8;