From 347509261bf66d0c48650e5634eac2eef8707a4b Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Sun, 21 Mar 2021 07:31:55 -0400 Subject: [PATCH] [mod_userdir] use stat_cache_path_isdir() --- src/mod_userdir.c | 5 ++--- src/t/test_mod_userdir.c | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mod_userdir.c b/src/mod_userdir.c index 73552ded..2170548a 100644 --- a/src/mod_userdir.c +++ b/src/mod_userdir.c @@ -5,11 +5,11 @@ #include "buffer.h" #include "log.h" #include "response.h" +#include "stat_cache.h" #include "plugin.h" #include -#include #include #include @@ -152,10 +152,9 @@ static handler_t mod_userdir_docroot_construct(request_st * const r, plugin_data /* XXX: future: might add cache; getpwnam() lookup is expensive */ struct passwd *pwd = getpwnam(u); if (pwd) { - struct stat st; buffer_copy_string(b, pwd->pw_dir); buffer_append_path_len(b, CONST_BUF_LEN(p->conf.path)); - if (0 != stat(b->ptr, &st) || !S_ISDIR(st.st_mode)) { + if (!stat_cache_path_isdir(b)) { return HANDLER_GO_ON; } } diff --git a/src/t/test_mod_userdir.c b/src/t/test_mod_userdir.c index d9db7c1f..b9c2f111 100644 --- a/src/t/test_mod_userdir.c +++ b/src/t/test_mod_userdir.c @@ -192,6 +192,11 @@ int http_response_redirect_to_directory(request_st *r, int status) { return 0; } +int stat_cache_path_isdir(const buffer *name) { + UNUSED(name); + return 1; +} + int config_plugin_values_init(server *srv, void *p_d, const config_plugin_keys_t *cpk, const char *mname) { UNUSED(srv); UNUSED(p_d);