From e9a424add17d5b86f40231c43af269ad432b6855 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 8 Apr 2019 13:55:58 +0200 Subject: [PATCH] Displaying directory tree sizes with -update and -update_r --- xorriso/cmp_update.c | 13 +++++++-- xorriso/disk_ops.c | 21 ++++++++------ xorriso/disk_ops.h | 13 ++++++++- xorriso/iso_tree.c | 55 +++++++++++++++++++++++++++++++------ xorriso/xorriso_timestamp.h | 2 +- xorriso/xorrisoburn.h | 6 ++++ 6 files changed, 89 insertions(+), 21 deletions(-) diff --git a/xorriso/cmp_update.c b/xorriso/cmp_update.c index 91fc4cf5..a9f61ad1 100644 --- a/xorriso/cmp_update.c +++ b/xorriso/cmp_update.c @@ -1,7 +1,7 @@ /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. - Copyright 2007-2014 Thomas Schmitt, + Copyright 2007-2019 Thomas Schmitt, 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); diff --git a/xorriso/disk_ops.c b/xorriso/disk_ops.c index 46afd598..caf45959 100644 --- a/xorriso/disk_ops.c +++ b/xorriso/disk_ops.c @@ -1,7 +1,7 @@ /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. - Copyright 2007-2016 Thomas Schmitt, + Copyright 2007-2019 Thomas Schmitt, 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,13 +564,15 @@ revoke_sorting:; report_size= sub_size/1024; if(report_size*1024sh_style_result) - sprintf(xorriso->result_line, "%-7.f ",(double) (report_size)); - else - sprintf(xorriso->result_line, "%7.f ",(double) (report_size)); - sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n", - Xorriso_esc_filepath(xorriso,show_path, sfe, 0)); - Xorriso_result(xorriso, 0); + if(!(flag & 4)) { + if(xorriso->sh_style_result) + sprintf(xorriso->result_line, "%-7.f ",(double) (report_size)); + else + sprintf(xorriso->result_line, "%7.f ",(double) (report_size)); + sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n", + Xorriso_esc_filepath(xorriso,show_path, sfe, 0)); + Xorriso_result(xorriso, 0); + } } ret= 1; @@ -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, diff --git a/xorriso/disk_ops.h b/xorriso/disk_ops.h index f4b301c5..90a9ddcd 100644 --- a/xorriso/disk_ops.h +++ b/xorriso/disk_ops.h @@ -1,7 +1,7 @@ /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. - Copyright 2007-2010 Thomas Schmitt, + Copyright 2007-2019 Thomas Schmitt, 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 diff --git a/xorriso/iso_tree.c b/xorriso/iso_tree.c index 2059c786..3be888e7 100644 --- a/xorriso/iso_tree.c +++ b/xorriso/iso_tree.c @@ -1,7 +1,7 @@ /* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images. - Copyright 2007-2016 Thomas Schmitt, + Copyright 2007-2019 Thomas Schmitt, 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,13 +1518,15 @@ much_too_long:; report_size= sub_size/1024; if(report_size*1024sh_style_result) - sprintf(xorriso->result_line, "%-7.f ",(double) (report_size)); - else - sprintf(xorriso->result_line, "%7.f ",(double) (report_size)); - sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n", - Xorriso_esc_filepath(xorriso, show_path, sfe, 0)); - Xorriso_result(xorriso, 0); + if(!(flag & 4)) { + if(xorriso->sh_style_result) + sprintf(xorriso->result_line, "%-7.f ",(double) (report_size)); + else + sprintf(xorriso->result_line, "%7.f ",(double) (report_size)); + sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n", + Xorriso_esc_filepath(xorriso, show_path, sfe, 0)); + Xorriso_result(xorriso, 0); + } } ret= 1; ex:; @@ -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(). diff --git a/xorriso/xorriso_timestamp.h b/xorriso/xorriso_timestamp.h index d3e2e625..2c907297 100644 --- a/xorriso/xorriso_timestamp.h +++ b/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2019.02.18.121941" +#define Xorriso_timestamP "2019.04.08.115541" diff --git a/xorriso/xorrisoburn.h b/xorriso/xorrisoburn.h index 353255a8..d1324aca 100644 --- a/xorriso/xorrisoburn.h +++ b/xorriso/xorrisoburn.h @@ -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.