From 3f0a6c8f9d7405da50e54fd9b7b7c042f9d36fb1 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 1 Aug 2022 17:06:43 +0200 Subject: [PATCH] sys/shell: improve 'ncget' command Allow to specify destination directory and concat the filename automatically. --- sys/shell/commands/sc_nanocoap_vfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sys/shell/commands/sc_nanocoap_vfs.c b/sys/shell/commands/sc_nanocoap_vfs.c index e9fd5ba730..c9ccf13eb7 100644 --- a/sys/shell/commands/sc_nanocoap_vfs.c +++ b/sys/shell/commands/sc_nanocoap_vfs.c @@ -121,7 +121,16 @@ static int _nanocoap_get_handler(int argc, char **argv) } dst = buffer; } else { + char *filename = strrchr(url, '/'); dst = argv[2]; + if (_is_dir(dst) && filename) { + if (snprintf(buffer, sizeof(buffer), "%s%s", + dst, filename + 1) >= (int)sizeof(buffer)) { + printf("Output file path too long\n"); + return -ENOBUFS; + } + dst = buffer; + } } /* alternatively write the file to stdout */