From 4c31bd16896e557a11a415e1b8569c425599d8e8 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 4 Aug 2022 14:54:44 +0200 Subject: [PATCH 1/2] sys/shell: add CONFIG_NCGET_DEFAULT_DATA_DIR option --- sys/shell/commands/sc_nanocoap_vfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/shell/commands/sc_nanocoap_vfs.c b/sys/shell/commands/sc_nanocoap_vfs.c index c9ccf13eb7..a145426afc 100644 --- a/sys/shell/commands/sc_nanocoap_vfs.c +++ b/sys/shell/commands/sc_nanocoap_vfs.c @@ -28,6 +28,13 @@ #include "shell.h" #include "vfs_default.h" +/** + * @brief Default download location for ncget + */ +#ifndef CONFIG_NCGET_DEFAULT_DATA_DIR +#define CONFIG_NCGET_DEFAULT_DATA_DIR VFS_DEFAULT_DATA +#endif + struct dir_list_ctx { char *buf; char *cur; @@ -96,7 +103,7 @@ static int _nanocoap_get_handler(int argc, char **argv) if (argc < 2) { printf("Usage: %s [destination]\n", argv[0]); - printf("Default destination: %s\n", VFS_DEFAULT_DATA); + printf("Default destination: %s\n", CONFIG_NCGET_DEFAULT_DATA_DIR); return -EINVAL; } @@ -115,7 +122,7 @@ static int _nanocoap_get_handler(int argc, char **argv) return -EINVAL; } if (snprintf(buffer, sizeof(buffer), "%s%s", - VFS_DEFAULT_DATA, dst) >= (int)sizeof(buffer)) { + CONFIG_NCGET_DEFAULT_DATA_DIR, dst) >= (int)sizeof(buffer)) { printf("Output file path too long\n"); return -ENOBUFS; } From 51804679e6173826957e530608722041b9d58022 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 5 Aug 2022 12:10:22 +0200 Subject: [PATCH 2/2] sys/shell: ncget: make use of vfs_is_dir() --- sys/Makefile.dep | 4 ++++ sys/shell/commands/sc_nanocoap_vfs.c | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sys/Makefile.dep b/sys/Makefile.dep index 1295d3d404..42aec6c089 100644 --- a/sys/Makefile.dep +++ b/sys/Makefile.dep @@ -322,6 +322,10 @@ ifneq (,$(filter shell_commands,$(USEMODULE))) USEMODULE += netutils endif + ifneq (,$(filter nanocoap_vfs,$(USEMODULE))) + USEMODULE += vfs_util + endif + ifneq (,$(filter nimble_netif,$(USEMODULE))) USEMODULE += nimble_scanner USEMODULE += nimble_scanlist diff --git a/sys/shell/commands/sc_nanocoap_vfs.c b/sys/shell/commands/sc_nanocoap_vfs.c index a145426afc..9585802894 100644 --- a/sys/shell/commands/sc_nanocoap_vfs.c +++ b/sys/shell/commands/sc_nanocoap_vfs.c @@ -27,6 +27,7 @@ #include "net/nanocoap_vfs.h" #include "shell.h" #include "vfs_default.h" +#include "vfs_util.h" /** * @brief Default download location for ncget @@ -130,9 +131,9 @@ static int _nanocoap_get_handler(int argc, char **argv) } else { char *filename = strrchr(url, '/'); dst = argv[2]; - if (_is_dir(dst) && filename) { + if (vfs_is_dir(dst) > 0 && filename) { if (snprintf(buffer, sizeof(buffer), "%s%s", - dst, filename + 1) >= (int)sizeof(buffer)) { + dst, filename) >= (int)sizeof(buffer)) { printf("Output file path too long\n"); return -ENOBUFS; }