summaryrefslogtreecommitdiff
path: root/lib/fstree/gen_file_list.c
blob: c1cde51ec8b89886ba03b680b4dd011abdccaf0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * gen_file_list.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#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);
}