From a05fc07db7c6e6a84b29f5170f954f57fb37bb0e Mon Sep 17 00:00:00 2001 From: halex Date: Wed, 1 Sep 2021 18:16:52 +0000 Subject: [PATCH] consider two files sharing the same inode identical This gives a substantial speedup when comparing directory structures with many hardlinked files, e.g. when using rsnapshot for incremental backup. ok stsp@ millert@ --- usr.bin/diff/diffreg.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index e834fd4aae3..ae49b7f25a3 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: diffreg.c,v 1.93 2019/06/28 13:35:00 deraadt Exp $ */ +/* $OpenBSD: diffreg.c,v 1.94 2021/09/01 18:16:52 halex Exp $ */ /* * Copyright (C) Caldera International Inc. 2001-2002. @@ -429,6 +429,10 @@ files_differ(FILE *f1, FILE *f2, int flags) if ((flags & (D_EMPTY1|D_EMPTY2)) || stb1.st_size != stb2.st_size || (stb1.st_mode & S_IFMT) != (stb2.st_mode & S_IFMT)) return (1); + + if (stb1.st_dev == stb2.st_dev && stb1.st_ino == stb2.st_ino) + return (0); + for (;;) { i = fread(buf1, 1, sizeof(buf1), f1); j = fread(buf2, 1, sizeof(buf2), f2); -- 2.20.1