Displaying directory tree sizes with -update and -update_r

This commit is contained in:
Thomas Schmitt 2019-04-08 13:55:58 +02:00
parent 1ff09139d4
commit e9a424add1
6 changed files with 89 additions and 21 deletions

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2014 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2019 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -796,7 +796,7 @@ int Xorriso_update_interpreter(struct XorrisO *xorriso,
int split_count= 0;
char *part_path= NULL, *part_name;
int partno, total_parts, new_total_parts, added_overwrote= 0;
off_t offset, bytes, total_bytes, disk_size, first_bytes;
off_t offset, bytes, total_bytes, disk_size, first_bytes, du_size;
if((compare_result&3)==3) {
sprintf(xorriso->info_text, "Missing on disk and in ISO: disk_path ");
@ -1015,6 +1015,15 @@ overwrite:;
xorriso->info_text + strlen(xorriso->info_text), 5, 1e4,
1 | 2);
strcat(xorriso->info_text, ")");
} else if (ret == 0 && S_ISDIR(stbuf.st_mode)) {
ret= Xorriso_get_dus(xorriso, iso_rr_path, &du_size, (off_t) 0, 0);
if(ret > 0 && du_size > 0) {
strcat(xorriso->info_text, " (");
Sfile_scale((double) du_size,
xorriso->info_text + strlen(xorriso->info_text), 5, 1e4,
1 | 2);
strcat(xorriso->info_text, ")");
}
}
}
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2016 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2019 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -343,6 +343,7 @@ int Xorriso_hop_link(struct XorrisO *xorriso, char *link_path,
/* @param flag bit0= do not only sum up sizes but also print subdirs
bit1= this is a recursion
bit2= do not report result by Xorriso_result()
@return <=0 error , 1 ok , 2 could not open directory
*/
int Xorriso_show_dux_subs(struct XorrisO *xorriso,
@ -563,6 +564,7 @@ revoke_sorting:;
report_size= sub_size/1024;
if(report_size*1024<sub_size)
report_size++;
if(!(flag & 4)) {
if(xorriso->sh_style_result)
sprintf(xorriso->result_line, "%-7.f ",(double) (report_size));
else
@ -571,6 +573,7 @@ revoke_sorting:;
Xorriso_esc_filepath(xorriso,show_path, sfe, 0));
Xorriso_result(xorriso, 0);
}
}
ret= 1;
ex:;
@ -902,7 +905,7 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd,
if(ret<=0)
link_target[0]= 0;
}
} else if(flag&4) { /* -du or -dus */
} else if(flag&4) { /* -dux or -dusx */
size= stbuf.st_size;
if(S_ISDIR(stbuf.st_mode)) {
ret= Xorriso_show_dux_subs(xorriso, path, filev[i], &size, boss_mem,

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2010 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2019 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -45,6 +45,17 @@ int Xorriso_format_ls_l(struct XorrisO *xorriso, struct stat *stbuf, int flag);
int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd,
int filec, char **filev, off_t boss_mem, int flag);
/* @param flag bit0= do not only sum up sizes but also print subdirs
bit1= this is a recursion
bit2= do not report result by Xorriso_result()
@return <=0 error , 1 ok , 2 could not open directory
*/
int Xorriso_show_dux_subs(struct XorrisO *xorriso,
char *abs_path, char *rel_path, off_t *size,
off_t boss_mem,
struct LinkiteM *link_stack,
int flag);
/*
@param flag >>> bit0= remove whole sub tree: rm -r
bit1= remove empty directory: rmdir

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2016 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2019 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -1400,6 +1400,8 @@ int Xorriso_make_md5(struct XorrisO *xorriso, void *in_node, char *path,
/* @param flag bit0= do not only sum up sizes but also print subdirs
bit2= do not report result by Xorriso_result()
*/
int Xorriso_show_du_subs(struct XorrisO *xorriso, IsoDir *dir_node,
char *abs_path, char *rel_path, off_t *size,
@ -1516,6 +1518,7 @@ much_too_long:;
report_size= sub_size/1024;
if(report_size*1024<sub_size)
report_size++;
if(!(flag & 4)) {
if(xorriso->sh_style_result)
sprintf(xorriso->result_line, "%-7.f ",(double) (report_size));
else
@ -1524,6 +1527,7 @@ much_too_long:;
Xorriso_esc_filepath(xorriso, show_path, sfe, 0));
Xorriso_result(xorriso, 0);
}
}
ret= 1;
ex:;
Xorriso_free_meM(sfe);
@ -1844,6 +1848,41 @@ ex:;
}
/*
@return: <=0 = error, 1= directory tree, 2= path leads to non-directory
*/
int Xorriso_get_dus(struct XorrisO *xorriso, char *iso_rr_path, off_t *size,
off_t boss_mem, int flag)
{
int ret;
IsoNode *node;
char *path= NULL;
struct stat stbuf;
Xorriso_alloc_meM(path, char, SfileadrL);
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, iso_rr_path, path,
1 | 2 | 4);
if(ret <= 0)
goto ex;
ret= Xorriso_fake_stbuf(xorriso, path, &stbuf, &node, 0);
if(ret <= 0)
goto ex;
if(!S_ISDIR(stbuf.st_mode)) {
*size= stbuf.st_size;
ret= 2; goto ex;
}
ret= Xorriso_show_du_subs(xorriso, (IsoDir *) node, path, iso_rr_path, size,
boss_mem, 4);
if(ret <= 0)
goto ex;
ret= 1;
ex:
Xorriso_free_meM(path);
return(ret);
}
/* This function needs less buffer memory than Xorriso_ls_filev() but cannot
perform structured pattern matching as done by Xorriso_expand_pattern()
for subsequent Xorriso_ls_filev().

View File

@ -1 +1 @@
#define Xorriso_timestamP "2019.02.18.121941"
#define Xorriso_timestamP "2019.04.08.115541"

View File

@ -151,6 +151,12 @@ int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
*/
int Xorriso_ls(struct XorrisO *xorriso, int flag);
/*
@return: <=0 = error, 1= directory tree, 2= path leads to non-directory
*/
int Xorriso_get_dus(struct XorrisO *xorriso, char *iso_rr_path, off_t *size,
off_t boss_mem, int flag);
/* @param wd Path to prepend in case img_path is not absolute
@param img_path Absolute or relative path to be normalized
@param eff_path returns resulting effective path.