mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
gcoap/fileserver: recursive directory deletion as default
This commit is contained in:
parent
70a8cf0d63
commit
f357d99396
@ -26,8 +26,10 @@
|
||||
* In opposite, the If-None-Match option requires a request to be processed,
|
||||
* only if the resource does not yet exist, and is most useful for file creation.
|
||||
*
|
||||
* Directories are expressed to URIs with trailing slashes and can be DELETEd
|
||||
* when empty.
|
||||
* Directories are expressed to URIs with trailing slashes. Directories and
|
||||
* their content are deleted as if one would do an `$rm -r`. If you only would
|
||||
* like to delete a directory if it is empty, you must supply an If-Match option
|
||||
* with the special value @ref COAPFILESERVER_DIR_DELETE_ETAG.
|
||||
*
|
||||
* @note The file server uses ETag for cache validation. The ETags are built
|
||||
* from the file system stat values. As clients rely on the ETag to differ when
|
||||
@ -80,6 +82,12 @@ extern "C" {
|
||||
|
||||
#include "net/nanocoap.h"
|
||||
|
||||
/**
|
||||
* @brief Randomly generated Etag, used by a client when a directory should only be
|
||||
* deleted, if it is empty
|
||||
*/
|
||||
#define COAPFILESERVER_DIR_DELETE_ETAG (0x6ce88b56u)
|
||||
|
||||
/**
|
||||
* @brief File server handler
|
||||
*
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "net/gcoap/fileserver.h"
|
||||
#include "net/gcoap.h"
|
||||
#include "vfs.h"
|
||||
#include "vfs_util.h"
|
||||
|
||||
#define ENABLE_DEBUG 0
|
||||
#include "debug.h"
|
||||
@ -456,10 +457,19 @@ static ssize_t _delete_directory(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
||||
{
|
||||
int err;
|
||||
if (request->options.exists.if_match && request->options.if_match_len) {
|
||||
return gcoap_fileserver_error_handler(pdu, buf, len, COAP_CODE_PRECONDITION_FAILED);
|
||||
if (request->options.if_match != byteorder_htonl(COAPFILESERVER_DIR_DELETE_ETAG).u32) {
|
||||
return gcoap_fileserver_error_handler(pdu, buf, len, COAP_CODE_PRECONDITION_FAILED);
|
||||
}
|
||||
if ((err = vfs_rmdir(request->namebuf)) < 0) {
|
||||
return gcoap_fileserver_error_handler(pdu, buf, len, err);
|
||||
}
|
||||
}
|
||||
if ((err = vfs_rmdir(request->namebuf)) < 0) {
|
||||
return gcoap_fileserver_error_handler(pdu, buf, len, err);
|
||||
else if (IS_USED(MODULE_VFS_UTIL)) {
|
||||
if ((err = vfs_unlink_recursive(request->namebuf,
|
||||
request->namebuf,
|
||||
sizeof(request->namebuf))) < 0) {
|
||||
gcoap_fileserver_error_handler(pdu, buf, len, err);
|
||||
}
|
||||
}
|
||||
gcoap_resp_init(pdu, buf, len, COAP_CODE_DELETED);
|
||||
return coap_opt_finish(pdu, COAP_OPT_FINISH_NONE);
|
||||
|
Loading…
Reference in New Issue
Block a user