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

This commit is contained in:
Thomas Schmitt 2009-04-06 10:08:48 +00:00
parent e44a0fe6df
commit c74440e27b
3 changed files with 144 additions and 11 deletions

View File

@ -2,7 +2,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "Apr 05, 2009"
.TH XORRISO 1 "Apr 06, 2009"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -1094,6 +1094,8 @@ original content from stdin and writing to stdout whatever they want.
They must deliver the same output on the same input in repeated runs.
.br
Options are:
.br
"default" means that no other option is intended.
.br
"suffix=..." sets a file name suffix. If it is not empty then it will be
appended to the file name or removed from it.
@ -1134,12 +1136,14 @@ By default they are banned if xorriso runs under setuid permission.
.TP
\fB\-set_filter\fR name iso_rr_path [***]
Apply an -external_filter to the given data files in the ISO image.
If the filter suffix is not empty , then it will be appended to the file name.
If the filter suffix is not empty , then it will be applied to the file name.
Renaming only happens if the filter really gets attached and is not revoked by
its options. Files which already bear the suffix will not get filtered.
its options.
By default files which already bear the suffix will not get filtered. The
others will get the suffix appended to their names.
If the filter has option "remove_suffix", then the filter will only be
applied if the suffix is present and can be removed.
Name collisons caused by suffix change will prevent filtering.
Name oversize or collision caused by suffix change will prevent filtering.
.br
This command will immediately run the filter once for each file
in order to determine the output size.
@ -1151,10 +1155,9 @@ output from the first run. Filtering for image generation does not happen
with files from the loaded ISO image if the write method of growing is in
effect (i.e -indev and -outdev are identical).
.br
The reserved filter name "--remove-all-filters" revokes filtering. A suffix
may be appended after a "+" or "-". "-" will restrict the filter removal
to files with that suffix and remove it from the file name. "+" will only
process files without that suffix and add it to the name.
The reserved filter name "--remove-all-filters" revokes filtering. This will
revoke eventual suffix renamings as well. Use "--remove-all-filters+" to
prevent any suffix renaming.
.TP
\fB\-set_filter_r\fR name isuffix iso_rr_path [***]
Like -set_filter but affecting all data files below eventual directories.

View File

@ -1 +1 @@
#define Xorriso_timestamP "2009.04.05.143043"
#define Xorriso_timestamP "2009.04.06.100802"

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;