#include <fcntl.h>
#define BUFFER_SIZE 4096
+#define LARGE_BUFFER_SIZE 65536
typedef int64_t size_sum_t;
int ignore_dotfiles = 0; /* 1 means ignore files and directories
starting with a dot */
+int ignore_empty_files = 0; /* 1 means ignore empty files */
+
int show_realpaths = 0; /* 1 means ignore files and directories
starting with a dot */
int same_content(struct file_with_size *f1, struct file_with_size *f2) {
int fd1, fd2, s1, s2;
- char buffer1[BUFFER_SIZE], buffer2[BUFFER_SIZE];
+ char buffer1[LARGE_BUFFER_SIZE], buffer2[LARGE_BUFFER_SIZE];
fd1 = open(f1->filename, O_RDONLY);
fd2 = open(f2->filename, O_RDONLY);
if(fd1 >= 0 && fd2 >= 0) {
while(1) {
- s1 = read(fd1, buffer1, BUFFER_SIZE);
- s2 = read(fd2, buffer2, BUFFER_SIZE);
+ s1 = read(fd1, buffer1, LARGE_BUFFER_SIZE);
+ s2 = read(fd2, buffer2, LARGE_BUFFER_SIZE);
if(s1 < 0 || s2 < 0) {
close(fd1);
closedir(dir);
} else {
if(S_ISREG(sb.st_mode)) {
- tmp = safe_malloc(sizeof(struct file_with_size));
- tmp->next = tail;
- tmp->filename = strdup(name);
- tmp->size = sb.st_size;
- tmp->inode = sb.st_ino;
- tmp->group_id = -1;
- tail = tmp;
+ if(!ignore_entry(name)) {
+ if(!ignore_empty_files || sb.st_size > 0) {
+ tmp = safe_malloc(sizeof(struct file_with_size));
+ tmp->next = tail;
+ tmp->filename = strdup(name);
+ tmp->size = sb.st_size;
+ tmp->inode = sb.st_ino;
+ tmp->group_id = -1;
+ tail = tmp;
+ }
+ }
}
}
}
for(node2 = list2; node2; node2 = node2->next) {
- if(same_files(node1, node2)) {
- if(node1->group_id < 0) {
- if(node2->group_id >= 0) {
- node1->group_id = node2->group_id;
- } else {
- node1->group_id = k;
- k++;
+ if(node1->group_id < 0 || node2->group_id < 0) {
+ if(same_files(node1, node2)) {
+ if(node1->group_id < 0) {
+ if(node2->group_id >= 0) {
+ node1->group_id = node2->group_id;
+ } else {
+ node1->group_id = k;
+ k++;
+ }
+ }
+ if(node2->group_id < 0) {
+ node2->group_id = node1->group_id;
}
- }
- if(node2->group_id < 0) {
- node2->group_id = node1->group_id;
}
}
}
print_result(list1, list2);
file_list_delete(list1);
+
if(dirname2) {
file_list_delete(list2);
}
fprintf(out, "\n");
fprintf(out, " -h show this help\n");
fprintf(out, " -d ignore dot files and directories\n");
+ fprintf(out, " -0 ignore empty files\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");
setlocale (LC_ALL, "");
while (1) {
- c = getopt(argc, argv, "hrcgdp");
+ c = getopt(argc, argv, "hrcgd0p");
if (c == -1)
break;
ignore_dotfiles = 1;
break;
+ case '0':
+ ignore_empty_files = 1;
+ break;
+
case 'r':
show_realpaths = 1;
break;