diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Makemodule.am | 1 | ||||
| -rw-r--r-- | lib/fstree/gen_file_list.c | 36 | 
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/Makemodule.am b/lib/Makemodule.am index c6674c0..0cc1847 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -4,6 +4,7 @@ libfstree_a_SOURCES += lib/fstree/gen_inode_table.c lib/fstree/get_path.c  libfstree_a_SOURCES += lib/fstree/node_stat.c lib/fstree/mknode.c  libfstree_a_SOURCES += lib/fstree/add_by_path.c lib/fstree/xattr.c  libfstree_a_SOURCES += lib/fstree/node_from_path.c include/fstree.h +libfstree_a_SOURCES += lib/fstree/gen_file_list.c  libfstree_a_CFLAGS = $(AM_CFLAGS)  libfstree_a_CPPFLAGS = $(AM_CPPFLAGS) diff --git a/lib/fstree/gen_file_list.c b/lib/fstree/gen_file_list.c new file mode 100644 index 0000000..30cd2f6 --- /dev/null +++ b/lib/fstree/gen_file_list.c @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include "config.h" +#include "fstree.h" + +static file_info_t *file_list_dfs(tree_node_t *n) +{ +	if (S_ISREG(n->mode)) +		return n->data.file; + +	if (S_ISDIR(n->mode)) { +		file_info_t *list = NULL, *last = NULL; + +		for (n = n->data.dir->children; n != NULL; n = n->next) { +			if (list == NULL) { +				list = file_list_dfs(n); +				if (list == NULL) +					continue; +				last = list; +			} else { +				last->next = file_list_dfs(n); +			} + +			while (last->next != NULL) +				last = last->next; +		} + +		return list; +	} + +	return NULL; +} + +void fstree_gen_file_list(fstree_t *fs) +{ +	fs->files = file_list_dfs(fs->root); +}  | 
