You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/21 08:29:42 UTC
[incubator-nuttx-apps] branch master updated: netutils: webserver: Fix directory handling
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push:
new 6fb173e3d netutils: webserver: Fix directory handling
6fb173e3d is described below
commit 6fb173e3d59ea9c9b1fe02a0ac5f08ed0d342c35
Author: Masayuki Ishikawa <ma...@gmail.com>
AuthorDate: Fri Oct 21 15:21:50 2022 +0900
netutils: webserver: Fix directory handling
Summary:
- I noticed that the webserver can not handle a directory.
- This commit fixes this issue.
Impact:
- None
Testing:
- Tested with spresense:wifi_smp
Signed-off-by: Masayuki Ishikawa <Ma...@jp.sony.com>
---
netutils/webserver/httpd_dirlist.c | 6 +++---
netutils/webserver/httpd_sendfile.c | 11 ++++++++++-
2 files changed, 13 insertions(+), 4 deletions(-)
diff --git a/netutils/webserver/httpd_dirlist.c b/netutils/webserver/httpd_dirlist.c
index 8ab1a3f10..cf2e0114a 100644
--- a/netutils/webserver/httpd_dirlist.c
+++ b/netutils/webserver/httpd_dirlist.c
@@ -109,7 +109,7 @@ bool httpd_is_file(FAR const char *filename)
{
char *path;
int fd;
- bool ret = false;
+ bool ret = true;
path = malloc(CONFIG_NAME_MAX);
ASSERT(path);
@@ -117,12 +117,12 @@ bool httpd_is_file(FAR const char *filename)
snprintf(path, CONFIG_NAME_MAX, "%s/%s",
CONFIG_NETUTILS_HTTPD_PATH, filename);
- fd = open(path, O_RDONLY);
+ fd = open(path, O_DIRECTORY);
if (-1 != fd)
{
close(fd);
- ret = true;
+ ret = false;
}
free(path);
diff --git a/netutils/webserver/httpd_sendfile.c b/netutils/webserver/httpd_sendfile.c
index a54bdf262..58847fd7d 100644
--- a/netutils/webserver/httpd_sendfile.c
+++ b/netutils/webserver/httpd_sendfile.c
@@ -83,7 +83,16 @@ int httpd_sendfile_open(const char *name, struct httpd_fs_file *file)
file->len = (int) st.st_size;
- file->fd = open(file->path, O_RDONLY);
+ if (S_ISDIR(st.st_mode))
+ {
+ /* we assume -1 as a directory */
+
+ file->fd = -1;
+ }
+ else
+ {
+ file->fd = open(file->path, O_RDONLY);
+ }
#ifndef CONFIG_NETUTILS_HTTPD_DIRLIST
if (file->fd == -1)