New -find test -name_limit_blocker. Made -file_name_limit ready for loaded ISOs
This commit is contained in:
@ -2864,6 +2864,16 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
}
|
||||
ret= 1;
|
||||
|
||||
} else if(action == 54 || action == 56) { /* internal: truncate_name */
|
||||
ret= Xorriso_truncate_uniquely(xorriso, xorriso->file_name_limit,
|
||||
node, abs_path, show_path,
|
||||
2 * (action == 56));
|
||||
|
||||
} else if(action == 55 || action == 57) {
|
||||
/* internal: unique_trunc_test length (in type) */
|
||||
ret= Xorriso_truncate_uniquely(xorriso, type, node, abs_path, show_path,
|
||||
1 | (2 * (action == 57)));
|
||||
|
||||
} else { /* includes : 15 in_iso */
|
||||
Xorriso_esc_filepath(xorriso, show_path, xorriso->result_line, 0);
|
||||
strcat(xorriso->result_line, "\n");
|
||||
@ -3177,6 +3187,11 @@ return:
|
||||
ftest->boss->use_pattern= (strcmp(arg1, "off") != 0);
|
||||
value= 0;
|
||||
|
||||
break; case 24: /* -name_limit_blocker */
|
||||
ret= Xorriso_truncate_uniquely(xorriso, *((int *) arg1), node, path, path,
|
||||
1 | 4);
|
||||
value= (ret == 0);
|
||||
|
||||
break; default:
|
||||
|
||||
/* >>> complain about unknown test type */;
|
||||
@ -4262,32 +4277,186 @@ ex:
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= allow to increase limit for loaded image
|
||||
/* @param flag bit0= tolerate truncated files of old length
|
||||
and mangle collisions
|
||||
*/
|
||||
int Xorriso_set_file_name_limit(struct XorrisO *xorriso, int value, int flag)
|
||||
{
|
||||
int ret;
|
||||
IsoImage *volume= NULL;
|
||||
struct FindjoB *job= NULL;
|
||||
struct stat dir_stbuf;
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 1);
|
||||
if(ret < 0)
|
||||
return(ret);
|
||||
if (volume != NULL) {
|
||||
if(flag & 1) {
|
||||
|
||||
/* >>> check whether there are non-refreshable truncated names */;
|
||||
|
||||
/* >>> refresh truncation of names */;
|
||||
|
||||
iso_image_set_truncate_mode(volume, 1, value);
|
||||
} else {
|
||||
goto ex;
|
||||
if (ret == 1 && volume != NULL) {
|
||||
/* Check whether there are non-refreshable truncated names */
|
||||
ret= Findjob_new(&job, "/", 0);
|
||||
if(ret<=0) {
|
||||
Xorriso_no_findjob(xorriso, "xorriso", 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
Findjob_set_action_type(job, 55 + 2 * (flag & 1), value, 0);
|
||||
xorriso->find_unique_trunc_result= 2;
|
||||
ret= Xorriso_findi(xorriso, job, NULL, (off_t) 0, NULL, "/",
|
||||
&dir_stbuf, 0, 0);
|
||||
if(ret < 0)
|
||||
goto ex;
|
||||
xorriso->request_to_abort= 0;
|
||||
if(xorriso->find_unique_trunc_result == 0 && !(flag & 1)) {
|
||||
Xorriso_msgs_submit(xorriso, 0,
|
||||
"-file_name_limit may not be changed because a drive is acquired",
|
||||
0, "SORRY", 0);
|
||||
return(0);
|
||||
"-file_name_limit may not be changed because truncated files exist or collisions would occur",
|
||||
0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
|
||||
xorriso->file_name_limit= value;
|
||||
iso_image_set_truncate_mode(volume, 1, value);
|
||||
|
||||
/* truncations are necessary */;
|
||||
if(xorriso->find_unique_trunc_result == 1) {
|
||||
Findjob_set_action_type(job, 54 + 2 * (flag & 1),
|
||||
xorriso->file_name_limit, 0);
|
||||
xorriso->find_unique_trunc_result= 2;
|
||||
ret= Xorriso_findi(xorriso, job, NULL, (off_t) 0, NULL, "/",
|
||||
&dir_stbuf, 0, 0);
|
||||
if(ret < 0)
|
||||
goto ex;
|
||||
if(xorriso->find_unique_trunc_result == 0) {
|
||||
|
||||
/* >>> Did not work . What to do ? */;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
xorriso->file_name_limit= value;
|
||||
return(1);
|
||||
ret= 1;
|
||||
ex:;
|
||||
Findjob_destroy(&job, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= test for uniqueness, do not change name
|
||||
bit1= tolerate existing truncated names and mangle collisions
|
||||
bit2= be silent about non-uniquely truncatables
|
||||
do not set xorriso->request_to_abort
|
||||
*/
|
||||
int Xorriso_truncate_uniquely(struct XorrisO *xorriso, int length,
|
||||
IsoNode *node, char *abs_path, char *show_path,
|
||||
int flag)
|
||||
{
|
||||
int ret, l, i;
|
||||
unsigned int mangleno;
|
||||
char *name, *trunc= NULL, *old_name= NULL;
|
||||
IsoDir *dir;
|
||||
IsoNode *collider;
|
||||
IsoImage *volume= NULL;
|
||||
|
||||
name= (char *) iso_node_get_name(node);
|
||||
l= strlen(name);
|
||||
|
||||
/* Check for truncated name */
|
||||
if(l == xorriso->file_name_limit && l != length && !(flag & 2)) {
|
||||
i= 0;
|
||||
if(name[l - 33] == ':') {
|
||||
for(i= l - 32; i < l; i++)
|
||||
if((name[i] < '0' || name[i] > '9') &&
|
||||
(name[i] < 'a' || name[i] > 'f'))
|
||||
break;
|
||||
}
|
||||
if(i == l) {
|
||||
if(!(flag & 4)) {
|
||||
sprintf(xorriso->info_text, "Truncated name of current limit found: ");
|
||||
Text_shellsafe(name, xorriso->info_text, 1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
}
|
||||
xorriso->find_unique_trunc_result= 0;
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
}
|
||||
|
||||
/* Check for need to truncate */
|
||||
if(l <= length)
|
||||
{ret= 1; goto ex;}
|
||||
|
||||
if(xorriso->find_unique_trunc_result > 1)
|
||||
xorriso->find_unique_trunc_result= 1;
|
||||
trunc= strdup(name);
|
||||
old_name= strdup(name);
|
||||
if(trunc == NULL || old_name == NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, NULL, 0);
|
||||
ret= -1; goto ex;
|
||||
}
|
||||
ret= iso_truncate_leaf_name(1, length, trunc, 0);
|
||||
if(ret < 0) {
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
Xorriso_report_iso_error(xorriso, "", ret,
|
||||
"Error when truncating file name", 0, "SORRY", 1);
|
||||
xorriso->find_unique_trunc_result= 0;
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
|
||||
dir= iso_node_get_parent(node);
|
||||
if(dir != NULL) {
|
||||
/* (intentionally using deprecated call which does not truncate by itself)*/
|
||||
ret= iso_dir_get_node(dir, trunc, &collider);
|
||||
if(ret == 1) {
|
||||
if((flag & 1) && !(flag & 2)) {
|
||||
if(!(flag & 4)) {
|
||||
sprintf(xorriso->info_text,
|
||||
"Truncated name collides with existing name: ");
|
||||
Text_shellsafe(name, xorriso->info_text, 1);
|
||||
strcat(xorriso->info_text, " -> ");
|
||||
Text_shellsafe(trunc, xorriso->info_text, 1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
}
|
||||
xorriso->find_unique_trunc_result= 0;
|
||||
{ret= 0; goto ex;}
|
||||
} else {
|
||||
/* Mangle */
|
||||
for(mangleno= 0; mangleno < 0xffffffff; mangleno++) {
|
||||
Sfile_flatten_utf8_heads(trunc, length - 33 - 9, 0);
|
||||
sprintf(trunc + length - 33 - 9, ":%-8.8X", mangleno);
|
||||
trunc [length - 33] = ':';
|
||||
ret= iso_dir_get_node(dir, trunc, &collider);
|
||||
if(ret == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* If only for testing: done now */
|
||||
if(flag & 1)
|
||||
{ret= 1; goto ex;}
|
||||
if(xorriso->file_name_limit != length)
|
||||
{ret= -1; goto ex;} /* Programming error */
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 1);
|
||||
if(ret < 0)
|
||||
{ret= -1; goto ex;} /* Programming error */
|
||||
|
||||
/* Set truncated name */
|
||||
ret= iso_image_set_node_name(volume, node, trunc, 0);
|
||||
if(ret < 0) {
|
||||
Xorriso_process_msg_queues(xorriso, 0);
|
||||
xorriso->find_unique_trunc_result= 0;
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
Xorriso_set_change_pending(xorriso, 0);
|
||||
sprintf(xorriso->info_text, "Truncated: ");
|
||||
Text_shellsafe(old_name, xorriso->info_text, 1);
|
||||
strcat(xorriso->info_text, " -> ");
|
||||
Text_shellsafe(trunc, xorriso->info_text, 1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
||||
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(ret == 0 && (flag & 1) && !(flag & 4))
|
||||
xorriso->request_to_abort= 1;
|
||||
Xorriso_free_meM(old_name);
|
||||
Xorriso_free_meM(trunc);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user