[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] canonicalize: only stat() when required
From: |
Pádraig Brady |
Subject: |
[PATCH] canonicalize: only stat() when required |
Date: |
Sat, 31 Dec 2011 11:16:36 +0000 |
* lib/canonicalize.c (canonicalize_filename_mode):
Avoid calling l?stat() when both CAN_MISSING,
and CAN_NOLINKS are set, as then we neither need
to resolve symlinks or test component existence.
---
ChangeLog | 8 ++++++++
lib/canonicalize.c | 9 ++++++++-
2 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ff9c84a..a95caf3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2011-12-31 Pádraig Brady <address@hidden>
+
+ canonicalize: only stat() if required
+ * lib/canonicalize.c (canonicalize_filename_mode):
+ Avoid calling l?stat() when both CAN_MISSING,
+ and CAN_NOLINKS are set, as we neither need
+ to resolve symlinks or test component existence.
+
2011-12-30 Pádraig Brady <address@hidden>
canonicalize: fix references to stat() and lstat()
diff --git a/lib/canonicalize.c b/lib/canonicalize.c
index e84c339..e5b69d9 100644
--- a/lib/canonicalize.c
+++ b/lib/canonicalize.c
@@ -198,7 +198,14 @@ canonicalize_filename_mode (const char *name,
canonicalize_mode_t can_mode)
dest += end - start;
*dest = '\0';
- if ((logical ? stat (rname, &st) : lstat (rname, &st)) != 0)
+ if (logical && (can_mode == CAN_MISSING))
+ {
+ /* Avoid the stat in this case as it's inconsequential.
+ i.e. we're neither resolving symlinks or testing
+ component existence. */
+ st.st_mode = 0;
+ }
+ else if ((logical ? stat (rname, &st) : lstat (rname, &st)) != 0)
{
saved_errno = errno;
if (can_mode == CAN_EXISTING)
--
1.7.6.4
- [PATCH] canonicalize: only stat() when required,
Pádraig Brady <=