New action estimate_size for -find and -findx

This commit is contained in:
2010-12-02 11:10:39 +00:00
parent 65fdba8884
commit 025d6f2ee6
10 changed files with 121 additions and 40 deletions

View File

@ -1688,6 +1688,29 @@ int Xorriso_set_hidden(struct XorrisO *xorriso, void *in_node, char *path,
}
/* @param flag bit0= increase only upper estimation
*/
int Xorriso_estimate_file_size(struct XorrisO *xorriso, struct FindjoB *job,
char *basename, mode_t st_mode, off_t st_size, int flag)
{
off_t upper, lower, size;
lower = 3 * strlen(basename) + 34; /* >>> + minimum RR ? */
upper = 3 * strlen(basename) + 2048;
if(S_ISREG(st_mode)) {
size= ((st_size + (off_t) 2047) / (off_t) 2048) * (off_t) 2048;
lower+= size;
upper+= size;
} else if(S_ISDIR(st_mode)) {
upper+= 4096;
}
job->estim_upper_size+= upper;
if(!(flag & 1))
job->estim_lower_size+= lower;
return(1);
}
int Xorriso_cannot_create_iter(struct XorrisO *xorriso, int iso_error,int flag)
{
Xorriso_process_msg_queues(xorriso,0);
@ -1823,9 +1846,9 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
gid_t group= 0;
time_t date= 0;
mode_t mode_or= 0, mode_and= ~1;
char *target, *text_2, sfe[5*SfileadrL], *iso_prefix, md5[16];
char *target, *text_2, sfe[5*SfileadrL], *iso_prefix, md5[16], *basename;
struct FindjoB *subjob;
struct stat dir_stbuf;
struct stat dir_stbuf, stbuf;
action= Findjob_get_action_parms(job, &target, &text_2, &user, &group,
&mode_and, &mode_or, &type, &date, &subjob, 0);
@ -1937,6 +1960,16 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
iso_node_set_sort_weight(node, type);
} else if(action == 39) { /* hide */
Xorriso_set_hidden(xorriso, node, NULL, type, 0);
} else if(action == 40) { /* estimate_size */
basename= strrchr(abs_path, '/');
if(basename != NULL)
basename++;
else
basename= abs_path;
ret= Xorriso_fake_stbuf(xorriso, "", &stbuf, &node, 1);
if(ret > 0)
ret= Xorriso_estimate_file_size(xorriso, job, basename, stbuf.st_mode,
stbuf.st_size, 0);
} else { /* includes : 15 in_iso */
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);