-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: Move validation out of lcfs_node_add_child()
Unfortunately at least ostree does: node = lcfs_node_new() lcfs_node_add_child(parent, node); lcfs_node_set_mode(node, ...) So we basically have a completely uninitialized node as part of the tree. This failed our basic "validate the mode" logic. We can't do any validation at all in `lcfs_node_add_child()` so move it to the first time we walk the tree as part of `lcfs_node_write_to()`. Also as part of fixing this: Today we don't really have coverage of the C library as it may be used by external consumers. Add a unit test to verify this, and we can build on this more. Signed-off-by: Colin Walters <walters@verbum.org>
- Loading branch information
Showing
6 changed files
with
43 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
libcomposefs/**/* | ||
tools/**/* | ||
tests/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#define _GNU_SOURCE | ||
|
||
#include "lcfs-writer.h" | ||
#include <assert.h> | ||
|
||
static inline void lcfs_node_unrefp(struct lcfs_node_s **nodep) | ||
{ | ||
if (*nodep != NULL) { | ||
lcfs_node_unref(*nodep); | ||
*nodep = NULL; | ||
} | ||
} | ||
#define cleanup_node __attribute__((cleanup(lcfs_node_unrefp))) | ||
|
||
static void test_add_uninitialized_child(void) | ||
{ | ||
cleanup_node struct lcfs_node_s *node = lcfs_node_new(); | ||
lcfs_node_set_mode(node, S_IFDIR | 0755); | ||
// libostree today does this pattern of creating an empty (uninitialized) | ||
// child and passing it to lcfs_node_add_child first. Verify this | ||
// continues to work for the forseeable future. | ||
cleanup_node struct lcfs_node_s *child = lcfs_node_new(); | ||
int r = lcfs_node_add_child(node, child, "somechild"); | ||
assert(r == 0); | ||
// Adding child took ownership | ||
child = NULL; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
test_add_uninitialized_child(); | ||
} |