TEST_ESP_OK( esp_vfs_unregister("") );
}
+TEST_CASE("vfs unregisters correct nested mount point", "[vfs]")
+{
+ dummy_vfs_t inst_foobar = {
+ .match_path = "/file",
+ .called = false
+ };
+ esp_vfs_t desc_foobar = DUMMY_VFS();
+ TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) );
+
+ dummy_vfs_t inst_foo = {
+ .match_path = "/bar/file",
+ .called = false
+ };
+ esp_vfs_t desc_foo = DUMMY_VFS();
+ TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) );
+
+ /* basic operation */
+ test_opened(&inst_foobar, "/foo/bar/file");
+ test_not_called(&inst_foo, "/foo/bar/file");
+
+ /* this should not match anything */
+ TEST_ESP_ERR(ESP_ERR_INVALID_STATE, esp_vfs_unregister("/foo/b"));
+
+ /* unregister "/foo" and check that we haven't unregistered "/foo/bar" */
+ TEST_ESP_OK( esp_vfs_unregister("/foo") );
+ test_not_called(&inst_foo, "/foo/bar/file");
+ test_opened(&inst_foobar, "/foo/bar/file");
+
+ /* repeat the above, with the reverse order of registration */
+ TEST_ESP_OK( esp_vfs_unregister("/foo/bar") );
+ TEST_ESP_OK( esp_vfs_register("/foo", &desc_foo, &inst_foo) );
+ TEST_ESP_OK( esp_vfs_register("/foo/bar", &desc_foobar, &inst_foobar) );
+ test_opened(&inst_foobar, "/foo/bar/file");
+ test_not_called(&inst_foo, "/foo/bar/file");
+ TEST_ESP_OK( esp_vfs_unregister("/foo") );
+ test_not_called(&inst_foo, "/foo/bar/file");
+ test_opened(&inst_foobar, "/foo/bar/file");
+ TEST_ESP_OK( esp_vfs_unregister("/foo/bar") );
+}
+
void test_vfs_register(const char* prefix, bool expect_success, int line)
{
esp_err_t esp_vfs_unregister(const char* base_path)
{
+ const size_t base_path_len = strlen(base_path);
for (size_t i = 0; i < s_vfs_count; ++i) {
vfs_entry_t* vfs = s_vfs[i];
if (vfs == NULL) {
continue;
}
- if (memcmp(base_path, vfs->path_prefix, vfs->path_prefix_len) == 0) {
+ if (base_path_len == vfs->path_prefix_len &&
+ memcmp(base_path, vfs->path_prefix, vfs->path_prefix_len) == 0) {
free(vfs);
s_vfs[i] = NULL;