]> granicus.if.org Git - esp-idf/commitdiff
Make relative paths match the default VFS, if provided
authorDeomid Ryabkov <rojer@cesanta.com>
Fri, 23 Jun 2017 12:07:43 +0000 (13:07 +0100)
committerDeomid Ryabkov <rojer@cesanta.com>
Fri, 23 Jun 2017 12:12:28 +0000 (13:12 +0100)
https://github.com/espressif/esp-idf/issues/158

components/vfs/test/test_vfs_paths.c
components/vfs/vfs.c

index fa00dc4e90e564adb1c53aee8435821c64d8c52b..e9ff6a0a0a30830f6a98064facf56033a1de0c5a 100644 (file)
@@ -197,6 +197,8 @@ TEST_CASE("vfs parses paths correctly", "[vfs]")
     test_dir_opened(&inst_foobar, "/foo/bar/file");
     inst_toplevel.match_path = "/tmp/foo";
     test_opened(&inst_toplevel, "/tmp/foo");
+    inst_toplevel.match_path = "foo";
+    test_opened(&inst_toplevel, "foo");
 
     TEST_ESP_OK( esp_vfs_unregister("/foo") );
     TEST_ESP_OK( esp_vfs_unregister("/foo1") );
index f610fd280ab032f60ff4598ca110a49a2dad41ba..f99465e4fd1bb82165d874c3409911a095d9027b 100644 (file)
@@ -142,6 +142,11 @@ static const vfs_entry_t* get_vfs_for_path(const char* path)
             memcmp(path, vfs->path_prefix, vfs->path_prefix_len) != 0) {
             continue;
         }
+        // this is the default VFS and we don't have a better match yet.
+        if (vfs->path_prefix_len == 0 && !best_match) {
+            best_match = vfs;
+            continue;
+        }
         // if path is not equal to the prefix, expect to see a path separator
         // i.e. don't match "/data" prefix for "/data1/foo.txt" path
         if (len > vfs->path_prefix_len &&