From: Francois Fleuret Date: Mon, 8 Mar 2010 19:56:08 +0000 (+0100) Subject: Added an option to see progress. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=78603b4d25cbe3325e9e48f4eba407d21e8a5adf;p=finddup.git Added an option to see progress. --- diff --git a/finddup.1 b/finddup.1 index cb7ad92..2d73865 100644 --- a/finddup.1 +++ b/finddup.1 @@ -33,6 +33,9 @@ do not show which files from DIR2 corresponds to files from DIR1 \fB-g\fR do not show the file group IDs (one group for each content) .TP +\fB-p\fR +show progress information in stderr +.TP \fB-r\fR shows the real path of the files @@ -42,13 +45,14 @@ The display is not sorted by groups. .SH "EXAMPLES" .nf -.B finddup -c blah something +.B finddup -cg blah something .fi List files found in .B ./blah/ which have a matching file with exact same content in .B ./something/ +without the group IDs .P .B finddup ./sources not:./backup @@ -60,7 +64,7 @@ which do not have content-matching equivalent in .B ./backup.sources .P -.B finddup -g ./tralala ./cuicui | sort -n +.B finddup ./tralala ./cuicui | sort -n .fi List groups of files with same content which exist both in diff --git a/finddup.c b/finddup.c index 7a20257..5dacc63 100644 --- a/finddup.c +++ b/finddup.c @@ -52,7 +52,7 @@ int ignore_dotfiles = 0; /* 1 means ignore files and directories int show_realpaths = 0; /* 1 means ignore files and directories starting with a dot */ -int show_progress = 1; /* 1 means show a progress bar when we are in a +int show_progress = 0; /* 1 means show a progress bar when we are in a tty */ int show_hits = 1; /* 1 means to show the files from dir2 @@ -253,6 +253,7 @@ void start(const char *dirname1, const char *dirname2) { struct file_with_size *node1, *node2; struct stat sb1, sb2; int not_in, found, same_dir; + int k, p, pp, l1, n; if(strncmp(dirname2, "not:", 4) == 0) { not_in = 1; @@ -273,18 +274,41 @@ void start(const char *dirname1, const char *dirname2) { same_dir = (sb1.st_ino == sb2.st_ino); - fprintf(stderr, "Scanning %s ... ", dirname1); + if(show_progress) { + fprintf(stderr, "Scanning %s ... ", dirname1); + } + list1 = scan_directory(0, dirname1); + if(same_dir) { list2 = list1; } else { - fprintf(stderr, "%s ... ", dirname2); + if(show_progress) { + fprintf(stderr, "%s ... ", dirname2); + } list2 = scan_directory(0, dirname2); } - fprintf(stderr, "done.\n"); + + if(show_progress) { + fprintf(stderr, "done.\n"); + } + + k = 0; + pp = -1; + n = 0; + l1 = file_list_length(list1); if(not_in) { for(node1 = list1; node1; node1 = node1->next) { + if(show_progress) { + p = (100 * n)/l1; + if(p > pp) { + fprintf(stderr, "%d%%\n", p); + pp = p; + } + n++; + } + found = 0; for(node2 = list2; !found && node2; node2 = node2->next) { @@ -303,9 +327,16 @@ void start(const char *dirname1, const char *dirname2) { } } else { - int k = 0; - for(node1 = list1; node1; node1 = node1->next) { + if(show_progress) { + p = (100 * n)/l1; + if(p > pp) { + fprintf(stderr, "%d%%\n", p); + pp = p; + } + n++; + } + for(node2 = list2; node2; node2 = node2->next) { if(node1->inode != node2->inode && same_files(node1, node2)) { if(node1->id < 0) { @@ -343,6 +374,7 @@ void print_help(FILE *out) { fprintf(out, " -d ignore dot files and directories\n"); fprintf(out, " -c do not show which files in DIR2 corresponds to those in DIR1\n"); fprintf(out, " -g do not show the file groups\n"); + fprintf(out, " -p show progress\n"); fprintf(out, " -r show the real file paths\n"); fprintf(out, "\n"); fprintf(out, "Report bugs and comments to \n"); @@ -359,7 +391,7 @@ int main(int argc, char **argv) { setlocale (LC_ALL, ""); while (1) { - c = getopt(argc, argv, "hrcgd"); + c = getopt(argc, argv, "hrcgdp"); if (c == -1) break; @@ -383,6 +415,10 @@ int main(int argc, char **argv) { show_groups = 0; break; + case 'p': + show_progress = 1; + break; + case 'c': show_hits = 0; break;