X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=finddup.c;h=5dacc63481c752e79d7d28f087bea2e06fe8600b;hb=78603b4d25cbe3325e9e48f4eba407d21e8a5adf;hp=514a67644c153d7f9ab7bab54e01f4d4b2b270aa;hpb=776548b8b43cfaf709d8f501ebb697c16e8d7832;p=finddup.git diff --git a/finddup.c b/finddup.c index 514a676..5dacc63 100644 --- a/finddup.c +++ b/finddup.c @@ -52,13 +52,13 @@ 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 corresponding to the ones from dir1 */ -int show_groups = 0; /* 1 means to show the group IDs when printing +int show_groups = 1; /* 1 means to show the group IDs when printing file names */ /********************************************************************/ @@ -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) { @@ -342,7 +373,8 @@ void print_help(FILE *out) { fprintf(out, " -h show this help\n"); 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 show the file groups\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; @@ -380,7 +412,11 @@ int main(int argc, char **argv) { break; case 'g': - show_groups = 1; + show_groups = 0; + break; + + case 'p': + show_progress = 1; break; case 'c':