Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: rename walker to path resolver. #139

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 224 additions & 30 deletions include/sqsh_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,187 @@ extern "C" {

struct SqshArchive;

/***************************************
* tree/path_resolver.c
*/

struct SqshPathResolver;

/**
* @brief Creates a new SqshPathResolver object at the root inode.
* @memberof SqshPathResolver
*
* @param[in] archive The archive to use
* @param[out] err Pointer to an int where the error code will be stored.
*
* @return a new file reader.
*/
struct SqshPathResolver *
sqsh_path_resolver_new(struct SqshArchive *archive, int *err);

/**
* @brief Moves the walker one level up
* @memberof SqshPathResolver
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_path_resolver_up(struct SqshPathResolver *walker);

/**
* @memberof SqshPathResolver
* @brief Moves the walker to the next entry int the current directory.
*
* @param[in,out] walker The walker to use
* @param[out] err Pointer to an int where the error code will be
* stored.
*
* @retval true if the walker was moved to the next entry.
* @retval false if the walker has no more entries to move to or an error
* occured.
*/
SQSH_NO_UNUSED bool
sqsh_path_resolver_next(struct SqshPathResolver *walker, int *err);

/**
* @brief Returns the inode type of the current entry.
* @memberof SqshPathResolver
*
* @param[in] walker The walker to use
*
* @return the inode type of the current entry.
*/
enum SqshFileType
sqsh_path_resolver_type(const struct SqshPathResolver *walker);

/**
* @brief Returns the name of the current entry. This entry is not zero
* terminated.
* @memberof SqshPathResolver
*
* @param[in] walker The walker to use
*
* @return the name of the current entry.
*/
const char *sqsh_path_resolver_name(const struct SqshPathResolver *walker);

/**
* @memberof SqshPathResolver
* @brief Returns the size of the name of the current entry.
*
* @param[in] walker The walker to use
*
* @return the size of the name of the current entry.
*/
uint16_t sqsh_path_resolver_name_size(const struct SqshPathResolver *walker);

/**
* @memberof SqshPathResolver
* @brief creates a heap allocated copy of the name of the current entry.
*
* The caller is responsible for calling free() on the returned pointer.
*
* The returned string is 0 terminated.
*
* @param[in] walker The walker to use
*
* @return the name of the current entry.
*/
SQSH_NO_UNUSED char *
sqsh_path_resolver_name_dup(const struct SqshPathResolver *walker);

/**
* @brief reverts the walker to the begining of the current directory.
* @memberof SqshPathResolver
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_path_resolver_revert(struct SqshPathResolver *walker);

/**
* @brief Looks up an entry in the current directory.
* @memberof SqshPathResolver
*
* @param[in,out] walker The walker to use
* @param[in] name The name of the entry to look up.
* @param[in] name_size The size of the name.
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_path_resolver_lookup(
struct SqshPathResolver *walker, const char *name,
const size_t name_size);

/**
* @brief Lets the walker enter the current entry.
* @memberof SqshPathResolver
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_path_resolver_down(struct SqshPathResolver *walker);

/**
* @brief Moves the walker to the root directory.
* @memberof SqshPathResolver
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_path_resolver_to_root(struct SqshPathResolver *walker);

/**
* @brief Returns the inode of the current entry.
* @memberof SqshPathResolver
*
* @param[in,out] walker The walker to use
* @param[out] err Pointer to an int where the error code will be
*
* @return the inode of the current entry.
*/
SQSH_NO_UNUSED struct SqshFile *
sqsh_path_resolver_open_file(const struct SqshPathResolver *walker, int *err);

/**
* @memberof SqshPathResolver
* @brief Resolve a path with the tree walker.
*
* This function will resolve the given path with the tree walker. The base is
* the current directory.
*
* @param[in,out] walker The walker to use
* @param[in] path The path to resolve.
* @param[in] follow_symlinks Whether to follow symlinks.
*
* @return the inode of the current entry.
*/
SQSH_NO_UNUSED int sqsh_path_resolver_resolve(
struct SqshPathResolver *walker, const char *path,
bool follow_symlinks);

/**
* @brief Cleans up resources used by a SqshPathResolver struct.
* @memberof SqshPathResolver
*
* @param[in,out] reader The file reader struct to clean up.
*
* @return 0 on success, less than 0 on error.
*/
int sqsh_path_resolver_free(struct SqshPathResolver *reader);

/***************************************
* tree/walker.c
*/

struct SqshTreeWalker;

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_new() instead.
* @brief Creates a new SqshTreeWalker object at the root inode.
* @memberof SqshTreeWalker
*
Expand All @@ -59,21 +233,25 @@ struct SqshTreeWalker;
*
* @return a new file reader.
*/
struct SqshTreeWalker *
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_new() "
"instead."))) struct SqshTreeWalker *
sqsh_tree_walker_new(struct SqshArchive *archive, int *err);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_up() instead.
* @brief Moves the walker one level up
* @memberof SqshTreeWalker
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_tree_walker_up(struct SqshTreeWalker *walker);
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_up() "
"instead."))) SQSH_NO_UNUSED int
sqsh_tree_walker_up(struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_tree_walker_next2() instead.
* @deprecated Since 1.2.0. Use sqsh_path_resolver_next() instead.
* @memberof SqshTreeWalker
* @brief Moves the walker to the next entry int the current directory.
*
Expand All @@ -84,36 +262,25 @@ SQSH_NO_UNUSED int sqsh_tree_walker_up(struct SqshTreeWalker *walker);
*
* @return 0 on success, less than 0 on error.
*/
__attribute__((deprecated("Since 1.2.0. Use sqsh_directory_walker_next2() "
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_next() "
"instead."))) SQSH_NO_UNUSED int
sqsh_tree_walker_next(struct SqshTreeWalker *walker);

/**
* @memberof SqshTreeWalker
* @brief Moves the walker to the next entry int the current directory.
*
* @param[in,out] walker The walker to use
* @param[out] err Pointer to an int where the error code will be
* stored.
*
* @retval true if the walker was moved to the next entry.
* @retval false if the walker has no more entries to move to or an error
* occured.
*/
SQSH_NO_UNUSED bool
sqsh_tree_walker_next2(struct SqshTreeWalker *walker, int *err);

/**
* @deprecated Since 1.2.0. Use sqsh_tree_walker_type() instead.
* @brief Returns the inode type of the current entry.
* @memberof SqshTreeWalker
*
* @param[in] walker The walker to use
*
* @return the inode type of the current entry.
*/
enum SqshFileType sqsh_tree_walker_type(const struct SqshTreeWalker *walker);
__attribute__((deprecated("Since 1.2.0. Use sqsh_tree_walker_type() "
"instead."))) enum SqshFileType
sqsh_tree_walker_type(const struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_tree_walker_name() instead.
* @brief Returns the name of the current entry. This entry is not zero
* terminated.
* @memberof SqshTreeWalker
Expand All @@ -122,19 +289,25 @@ enum SqshFileType sqsh_tree_walker_type(const struct SqshTreeWalker *walker);
*
* @return the name of the current entry.
*/
const char *sqsh_tree_walker_name(const struct SqshTreeWalker *walker);
__attribute__((deprecated("Since 1.2.0. Use sqsh_tree_walker_name() "
"instead."))) const char *
sqsh_tree_walker_name(const struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_tree_walker_name_size() instead.
* @memberof SqshTreeWalker
* @brief Returns the size of the name of the current entry.
*
* @param[in] walker The walker to use
*
* @return the size of the name of the current entry.
*/
uint16_t sqsh_tree_walker_name_size(const struct SqshTreeWalker *walker);
__attribute__((deprecated("Since 1.2.0. Use sqsh_tree_walker_name_size() "
"instead."))) uint16_t
sqsh_tree_walker_name_size(const struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_tree_walker_name_dup() instead.
* @memberof SqshTreeWalker
* @brief creates a heap allocated copy of the name of the current entry.
*
Expand All @@ -146,20 +319,25 @@ uint16_t sqsh_tree_walker_name_size(const struct SqshTreeWalker *walker);
*
* @return the name of the current entry.
*/
SQSH_NO_UNUSED char *
__attribute__((deprecated("Since 1.2.0. Use sqsh_tree_walker_name_dup() "
"instead."))) SQSH_NO_UNUSED char *
sqsh_tree_walker_name_dup(const struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_revert() instead.
* @brief reverts the walker to the begining of the current directory.
* @memberof SqshTreeWalker
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_tree_walker_revert(struct SqshTreeWalker *walker);
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_revert() "
"instead."))) SQSH_NO_UNUSED int
sqsh_tree_walker_revert(struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_lookup() instead.
* @brief Looks up an entry in the current directory.
* @memberof SqshTreeWalker
*
Expand All @@ -169,31 +347,40 @@ SQSH_NO_UNUSED int sqsh_tree_walker_revert(struct SqshTreeWalker *walker);
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_tree_walker_lookup(
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_lookup() "
"instead."))) SQSH_NO_UNUSED int
sqsh_tree_walker_lookup(
struct SqshTreeWalker *walker, const char *name,
const size_t name_size);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_down() instead.
* @brief Lets the walker enter the current entry.
* @memberof SqshTreeWalker
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_tree_walker_down(struct SqshTreeWalker *walker);
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_down() "
"instead."))) SQSH_NO_UNUSED int
sqsh_tree_walker_down(struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_to_root() instead.
* @brief Moves the walker to the root directory.
* @memberof SqshTreeWalker
*
* @param[in,out] walker The walker to use
*
* @return 0 on success, less than 0 on error.
*/
SQSH_NO_UNUSED int sqsh_tree_walker_to_root(struct SqshTreeWalker *walker);
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_to_root() "
"instead."))) SQSH_NO_UNUSED int
sqsh_tree_walker_to_root(struct SqshTreeWalker *walker);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_open_file() instead.
* @brief Returns the inode of the current entry.
* @memberof SqshTreeWalker
*
Expand All @@ -202,10 +389,12 @@ SQSH_NO_UNUSED int sqsh_tree_walker_to_root(struct SqshTreeWalker *walker);
*
* @return the inode of the current entry.
*/
SQSH_NO_UNUSED struct SqshFile *
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_open_file() "
"instead."))) SQSH_NO_UNUSED struct SqshFile *
sqsh_tree_walker_open_file(const struct SqshTreeWalker *walker, int *err);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_open_file() instead.
* @memberof SqshTreeWalker
* @brief Resolve a path with the tree walker.
*
Expand All @@ -218,18 +407,23 @@ sqsh_tree_walker_open_file(const struct SqshTreeWalker *walker, int *err);
*
* @return the inode of the current entry.
*/
SQSH_NO_UNUSED int sqsh_tree_walker_resolve(
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_resolve() "
"instead."))) SQSH_NO_UNUSED int
sqsh_tree_walker_resolve(
struct SqshTreeWalker *walker, const char *path, bool follow_symlinks);

/**
* @deprecated Since 1.2.0. Use sqsh_path_resolver_free() instead.
* @brief Cleans up resources used by a SqshTreeWalker struct.
* @memberof SqshTreeWalker
*
* @param[in,out] reader The file reader struct to clean up.
*
* @return 0 on success, less than 0 on error.
*/
int sqsh_tree_walker_free(struct SqshTreeWalker *reader);
__attribute__((deprecated("Since 1.2.0. Use sqsh_path_resolver_free() "
"instead."))) int
sqsh_tree_walker_free(struct SqshTreeWalker *reader);

#ifdef __cplusplus
}
Expand Down
Loading