[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Findutils-patches] [PATCH] For -samefile, skip stat if inode numbers di
From: |
James Youngman |
Subject: |
[Findutils-patches] [PATCH] For -samefile, skip stat if inode numbers differ. |
Date: |
Sat, 7 Mar 2009 21:13:30 +0000 |
* find/pred.c (pred_samefile): Skip stat if the inode numbers are
different.
Signed-off-by: James Youngman <address@hidden>
---
ChangeLog | 4 ++++
find/pred.c | 24 ++++++++++++++++++++++--
2 files changed, 26 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 3f21cc8..8ee70a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -29,6 +29,10 @@
(cost_table): Add NeedsInodeNumber.
(print_tree): Handle need_inum.
+ For -samefile, skip stat if inode numbers differ.
+ * find/pred.c (pred_samefile): Skip stat if the inode numbers are
+ different.
+
2009-03-06 James Youngman <address@hidden>
Updated translation po files from translationproject.org.
diff --git a/find/pred.c b/find/pred.c
index c51b4e7..142936b 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -1684,6 +1684,11 @@ pred_samefile (const char *pathname, struct stat
*stat_buf, struct predicate *pr
* same as the device number of the current directory, this
* predicate cannot return true. Hence there would be no need to
* stat the file we're looking at.
+ *
+ * For the moment, we simply compare inode numbers, which should cut
+ * down greatly on the number of calls to stat. Some of the
+ * remainder will be unnecessary, but the additional complexity
+ * probably isn't worthwhile.
*/
(void) pathname;
@@ -1691,8 +1696,23 @@ pred_samefile (const char *pathname, struct stat
*stat_buf, struct predicate *pr
* but that's just to ensure inode number stability by maintaining
* a reference to it; we don't need the file for anything else.
*/
- return stat_buf->st_ino == pred_ptr->args.samefileid.ino
- && stat_buf->st_dev == pred_ptr->args.samefileid.dev;
+ if (stat_buf->st_ino)
+ {
+ if (stat_buf->st_ino != pred_ptr->args.samefileid.ino)
+ return false;
+ }
+ /* Now stat the file to check the device number. */
+ if (0 == get_statinfo (pathname, state.rel_pathname, stat_buf))
+ {
+ /* the repeated test here is necessary in case stat_buf.st_ino had been
zero. */
+ return stat_buf->st_ino == pred_ptr->args.samefileid.ino
+ && stat_buf->st_dev == pred_ptr->args.samefileid.dev;
+ }
+ else
+ {
+ /* get_statinfo will already have emitted an error message. */
+ return false;
+ }
}
boolean
--
1.5.6.5