Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for ignore file content #160

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions fdupes.1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ exclude hidden files from consideration
.B -f --omitfirst
omit the first file in each set of matches
.TP
.B -c --ignore-content
ignore content, compare only file sizes
.TP
.B -1 --sameline
list each set of matches on a single line
.TP
Expand Down
73 changes: 57 additions & 16 deletions fdupes.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,13 @@ file_t **checkmatch(filetree_t **root, filetree_t *checktree, file_t *file)

if (cmpresult == 0) {
if (checktree->file->crcsignature == NULL) {
crcsignature = getcrcsignature(checktree->file->d_name, checktree->file->size);
if(ISFLAG(flags, F_IGNORECONTENT))
if(checktree->file->size >= 8192)
crcsignature = getcrcsignature(checktree->file->d_name, /*checktree->file->size*/(off_t)8192);
else
crcsignature = getcrcsignature(checktree->file->d_name,checktree->file->size);
else
crcsignature = getcrcsignature(checktree->file->d_name, checktree->file->size);
if (crcsignature == NULL) return NULL;

checktree->file->crcsignature = (md5_byte_t*) malloc(MD5_DIGEST_LENGTH * sizeof(md5_byte_t));
Expand All @@ -644,7 +650,13 @@ file_t **checkmatch(filetree_t **root, filetree_t *checktree, file_t *file)
}

if (file->crcsignature == NULL) {
crcsignature = getcrcsignature(file->d_name, file->size);
if(ISFLAG(flags, F_IGNORECONTENT))
if(file->size >= 8192)
crcsignature = getcrcsignature(file->d_name, /*file->size*/(off_t)8192);
else
crcsignature = getcrcsignature(file->d_name, file->size);
else
crcsignature = getcrcsignature(file->d_name,file->size);
if (crcsignature == NULL) return NULL;

file->crcsignature = (md5_byte_t*) malloc(MD5_DIGEST_LENGTH * sizeof(md5_byte_t));
Expand Down Expand Up @@ -708,6 +720,16 @@ int confirmmatch(FILE *file1, FILE *file2)
return 1;
}


int confirmmatch_ignore_content(FILE *file1, FILE *file2){
struct stat s1,s2;
fstat(fileno(file1), &s1);
fstat(fileno(file2), &s2);
if(s1.st_size == s2.st_size)
return 1;
return 0;
}

void summarizematches(file_t *files)
{
int numsets = 0;
Expand Down Expand Up @@ -1202,6 +1224,7 @@ void help_text()
printf(" -n --noempty exclude zero-length files from consideration\n");
printf(" -A --nohidden exclude hidden files from consideration\n");
printf(" -f --omitfirst omit the first file in each set of matches\n");
printf(" -c --ignore-content ignore content, compare only file sizes\n");
printf(" -1 --sameline list each set of matches on a single line\n");
printf(" -S --size show size of duplicate files\n");
printf(" -t --time show modification time of duplicate files\n");
Expand Down Expand Up @@ -1283,6 +1306,7 @@ int main(int argc, char **argv) {
{ "order", 1, 0, 'o' },
{ "reverse", 0, 0, 'i' },
{ "log", 1, 0, 'l' },
{"ignore-content",0,0,'c'},
{ 0, 0, 0, 0 }
};
#define GETOPT getopt_long
Expand All @@ -1296,7 +1320,7 @@ int main(int argc, char **argv) {

oldargv = cloneargs(argc, argv);

while ((opt = GETOPT(argc, argv, "frRq1StsHG:L:nAdPvhNImpo:il:"
while ((opt = GETOPT(argc, argv, "frRq1StsHG:L:nAdPvhNImpo:il:c"
#ifdef HAVE_GETOPT_H
, long_options, NULL
#endif
Expand Down Expand Up @@ -1326,6 +1350,9 @@ int main(int argc, char **argv) {
case 's':
SETFLAG(flags, F_FOLLOWLINKS);
break;
case 'c':
SETFLAG(flags, F_IGNORECONTENT);
break;
case 'H':
SETFLAG(flags, F_CONSIDERHARDLINKS);
break;
Expand Down Expand Up @@ -1488,20 +1515,34 @@ int main(int argc, char **argv) {
curfile = curfile->next;
continue;
}

if (confirmmatch(file1, file2)) {
if (ISFLAG(flags, F_DELETEFILES) && ISFLAG(flags, F_IMMEDIATE))
deletesuccessor(match, curfile,
ordertype == ORDER_MTIME ? sort_pairs_by_mtime :
ordertype == ORDER_CTIME ? sort_pairs_by_ctime :
sort_pairs_by_filename, loginfo );
else
registerpair(match, curfile,
ordertype == ORDER_MTIME ? sort_pairs_by_mtime :
ordertype == ORDER_CTIME ? sort_pairs_by_ctime :
sort_pairs_by_filename );
if(ISFLAG(flags, F_IGNORECONTENT)){
if (confirmmatch_ignore_content(file1, file2)) {
if (ISFLAG(flags, F_DELETEFILES) && ISFLAG(flags, F_IMMEDIATE))
deletesuccessor(match, curfile,
ordertype == ORDER_MTIME ? sort_pairs_by_mtime :
ordertype == ORDER_CTIME ? sort_pairs_by_ctime :
sort_pairs_by_filename, loginfo );
else
registerpair(match, curfile,
ordertype == ORDER_MTIME ? sort_pairs_by_mtime :
ordertype == ORDER_CTIME ? sort_pairs_by_ctime :
sort_pairs_by_filename );
}
}
else{
if (confirmmatch(file1, file2)) {
if (ISFLAG(flags, F_DELETEFILES) && ISFLAG(flags, F_IMMEDIATE))
deletesuccessor(match, curfile,
ordertype == ORDER_MTIME ? sort_pairs_by_mtime :
ordertype == ORDER_CTIME ? sort_pairs_by_ctime :
sort_pairs_by_filename, loginfo );
else
registerpair(match, curfile,
ordertype == ORDER_MTIME ? sort_pairs_by_mtime :
ordertype == ORDER_CTIME ? sort_pairs_by_ctime :
sort_pairs_by_filename );
}
}

fclose(file1);
fclose(file2);
}
Expand Down
2 changes: 1 addition & 1 deletion flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define F_IMMEDIATE 0x8000
#define F_PLAINPROMPT 0x10000
#define F_SHOWTIME 0x20000

#define F_IGNORECONTENT 0x40000
extern unsigned long flags;

#endif