From cdad5bceee79afbf8b3440b39c72890d2e67448d Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 26 Aug 2013 14:48:59 +0200 Subject: Avoid multiple stat() calls for same file As a side effect we can also not use the dirent.d_type field https://bugs.freedesktop.org/show_bug.cgi?id=68525 --- trust/save.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'trust/save.c') diff --git a/trust/save.c b/trust/save.c index a549d93..6533bd1 100644 --- a/trust/save.c +++ b/trust/save.c @@ -512,11 +512,11 @@ cleanup_directory (const char *directory, p11_dict *cache) { struct dirent *dp; + struct stat st; p11_dict *remove; p11_dictiter iter; char *path; DIR *dir; - int skip; bool ret; /* First we load all the modules */ @@ -535,18 +535,8 @@ cleanup_directory (const char *directory, if (asprintf (&path, "%s/%s", directory, dp->d_name) < 0) return_val_if_reached (false); -#ifdef HAVE_STRUCT_DIRENT_D_TYPE - if(dp->d_type != DT_UNKNOWN) { - skip = (dp->d_type == DT_DIR); - } else -#endif - { - struct stat st; - - skip = (stat (path, &st) < 0) || S_ISDIR (st.st_mode); - } - if (!skip) { + if (stat (path, &st) >= 0 && !S_ISDIR (st.st_mode)) { if (!p11_dict_set (remove, path, path)) return_val_if_reached (false); } else { -- cgit v1.2.1