You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2015/12/02 19:24:08 UTC

incubator-mynewt-larva git commit: nffs fix - allow trailing slash in nffs_readdir()

Repository: incubator-mynewt-larva
Updated Branches:
  refs/heads/master ddf578631 -> 770f4f28d


nffs fix - allow trailing slash in nffs_readdir()


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/770f4f28
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/770f4f28
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/770f4f28

Branch: refs/heads/master
Commit: 770f4f28db154112eb372ce5aa1948c7acb0f9a1
Parents: ddf5786
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Dec 2 10:23:40 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Dec 2 10:23:40 2015 -0800

----------------------------------------------------------------------
 libs/nffs/src/nffs_path.c               | 12 ++++++++++--
 libs/nffs/src/test/arch/sim/nffs_test.c | 21 +++++++++++++++++++--
 2 files changed, 29 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/770f4f28/libs/nffs/src/nffs_path.c
----------------------------------------------------------------------
diff --git a/libs/nffs/src/nffs_path.c b/libs/nffs/src/nffs_path.c
index bb1503f..8ab7f53 100644
--- a/libs/nffs/src/nffs_path.c
+++ b/libs/nffs/src/nffs_path.c
@@ -145,8 +145,16 @@ nffs_path_find(struct nffs_path_parser *parser,
                 return NFFS_ENOENT;
             }
 
-            rc = nffs_path_find_child(parent, parser->npp_token,
-                                      parser->npp_token_len, &inode_entry);
+            if (parser->npp_token_len == 0) {
+                /* If the path ends with a slash, the leaf is the parent, not
+                 * the trailing empty token.
+                 */
+                inode_entry = parent;
+                rc = 0;
+            } else {
+                rc = nffs_path_find_child(parent, parser->npp_token,
+                                          parser->npp_token_len, &inode_entry);
+            }
             goto done;
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/770f4f28/libs/nffs/src/test/arch/sim/nffs_test.c
----------------------------------------------------------------------
diff --git a/libs/nffs/src/test/arch/sim/nffs_test.c b/libs/nffs/src/test/arch/sim/nffs_test.c
index 2af2c46..40bef79 100644
--- a/libs/nffs/src/test/arch/sim/nffs_test.c
+++ b/libs/nffs/src/test/arch/sim/nffs_test.c
@@ -2201,8 +2201,8 @@ TEST_CASE(nffs_test_readdir)
     rc = nffs_opendir("/asdf", &dir);
     TEST_ASSERT(rc == NFFS_ENOENT);
 
-    /* Real directory. */
-    rc = nffs_opendir("/mydir", &dir);
+    /* Real directory (with trailing slash). */
+    rc = nffs_opendir("/mydir/", &dir);
     TEST_ASSERT_FATAL(rc == 0);
 
     rc = nffs_readdir(dir, &dirent);
@@ -2226,6 +2226,23 @@ TEST_CASE(nffs_test_readdir)
     rc = nffs_closedir(dir);
     TEST_ASSERT(rc == 0);
 
+    /* Root directory. */
+    rc = nffs_opendir("/", &dir);
+    TEST_ASSERT(rc == 0);
+    rc = nffs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+
+    nffs_test_util_assert_ent_name(dirent, "lost+found");
+    TEST_ASSERT(nffs_dirent_is_dir(dirent) == 1);
+
+    rc = nffs_readdir(dir, &dirent);
+    TEST_ASSERT(rc == 0);
+    nffs_test_util_assert_ent_name(dirent, "mydir");
+    TEST_ASSERT(nffs_dirent_is_dir(dirent) == 1);
+
+    rc = nffs_closedir(dir);
+    TEST_ASSERT(rc == 0);
+
     /* Delete entries while iterating. */
     rc = nffs_opendir("/mydir", &dir);
     TEST_ASSERT_FATAL(rc == 0);