2016-04-09 08:34:43 +03:00
|
|
|
// Copyright 2016-present Facebook. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// tree_path.h: declarations for the core path function for parsing and
|
|
|
|
// traversing a path through a tree.
|
|
|
|
//
|
|
|
|
// no-check-code
|
|
|
|
|
|
|
|
#ifndef __FASTMANIFEST_TREE_PATH_H__
|
|
|
|
#define __FASTMANIFEST_TREE_PATH_H__
|
|
|
|
|
|
|
|
#include "node.h"
|
2017-04-13 02:34:53 +03:00
|
|
|
#include "../portability/portability.h"
|
2016-04-09 08:34:43 +03:00
|
|
|
|
2016-04-18 21:36:43 +03:00
|
|
|
typedef struct _tree_state_changes_t {
|
|
|
|
ptrdiff_t size_change;
|
|
|
|
int32_t num_leaf_node_change;
|
|
|
|
bool non_arena_allocations;
|
|
|
|
bool checksum_dirty;
|
|
|
|
} tree_state_changes_t;
|
|
|
|
|
2016-04-09 08:34:43 +03:00
|
|
|
typedef enum {
|
|
|
|
TREE_ADD_CHILD_OK,
|
|
|
|
TREE_ADD_CHILD_OOM,
|
|
|
|
TREE_ADD_CHILD_WTF,
|
|
|
|
} tree_add_child_code_t;
|
|
|
|
typedef struct _tree_add_child_result_t {
|
|
|
|
tree_add_child_code_t code;
|
|
|
|
node_t *newroot;
|
|
|
|
node_t *newchild;
|
|
|
|
} tree_add_child_result_t;
|
|
|
|
|
|
|
|
typedef enum {
|
2016-05-17 02:20:57 +03:00
|
|
|
// walks the tree and searches for a leaf node. if the path cannot be found,
|
|
|
|
// exit with `FIND_PATH_NOT_FOUND`.
|
|
|
|
BASIC_WALK,
|
|
|
|
|
|
|
|
// walks the tree and searches for any node (including implicit nodes). if
|
|
|
|
// the path cannot be found, exit with `FIND_PATH_NOT_FOUND`.
|
|
|
|
BASIC_WALK_ALLOW_IMPLICIT_NODES,
|
2016-04-09 08:34:43 +03:00
|
|
|
|
|
|
|
// walks the tree. if the intermediate paths cannot be found, create them.
|
|
|
|
// if a leaf node exists where an intermediate path node needs to be
|
|
|
|
// created, then return `FIND_PATH_CONFLICT`.
|
2016-05-17 02:20:57 +03:00
|
|
|
CREATE_IF_MISSING,
|
2016-04-09 08:34:43 +03:00
|
|
|
|
|
|
|
// walks the tree. if the path cannot be found, exit with
|
|
|
|
// `FIND_PATH_NOT_FOUND`. if the operation is successful, then check
|
|
|
|
// intermediate nodes to ensure that they still have children. any nodes
|
|
|
|
// that do not should be removed.
|
2016-05-17 02:20:57 +03:00
|
|
|
REMOVE_EMPTY_IMPLICIT_NODES,
|
2016-04-09 08:34:43 +03:00
|
|
|
} find_path_operation_type;
|
|
|
|
typedef enum {
|
|
|
|
FIND_PATH_OK,
|
|
|
|
FIND_PATH_NOT_FOUND,
|
|
|
|
FIND_PATH_OOM,
|
|
|
|
FIND_PATH_CONFLICT,
|
|
|
|
FIND_PATH_WTF,
|
|
|
|
} find_path_result_t;
|
|
|
|
typedef struct _find_path_callback_result_t {
|
|
|
|
find_path_result_t code;
|
|
|
|
node_t *newroot;
|
|
|
|
} find_path_callback_result_t;
|
|
|
|
|
|
|
|
extern tree_add_child_result_t tree_add_child(
|
|
|
|
tree_t *tree,
|
|
|
|
node_t *const root_parent,
|
|
|
|
node_t *root,
|
|
|
|
const char *name, const size_t name_sz,
|
2016-04-18 21:40:15 +03:00
|
|
|
size_t num_children_hint,
|
2016-04-09 08:34:43 +03:00
|
|
|
tree_state_changes_t *changes);
|
|
|
|
|
|
|
|
extern find_path_result_t find_path(
|
|
|
|
tree_t *tree,
|
|
|
|
node_t *const root_parent,
|
|
|
|
node_t *root,
|
|
|
|
const char *path, const size_t path_sz,
|
|
|
|
find_path_operation_type operation_type,
|
|
|
|
tree_state_changes_t *changes,
|
|
|
|
find_path_callback_result_t (*callback)(
|
|
|
|
tree_t *tree,
|
|
|
|
node_t *const dir_parent,
|
|
|
|
node_t *dir,
|
|
|
|
const char *path, const size_t path_sz,
|
|
|
|
tree_state_changes_t *changes,
|
|
|
|
void *context),
|
|
|
|
void *context);
|
|
|
|
|
|
|
|
#endif // #ifndef __FASTMANIFEST_TREE_PATH_H__
|