diff options
Diffstat (limited to '')
-rw-r--r-- | c_hardflip.go | 2 | ||||
-rw-r--r-- | c_init.go | 15 | ||||
-rw-r--r-- | c_ldirs.go | 17 |
3 files changed, 29 insertions, 5 deletions
diff --git a/c_hardflip.go b/c_hardflip.go index 5351593..3243a3c 100644 --- a/c_hardflip.go +++ b/c_hardflip.go @@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_hardflip.go - * Wed Dec 20 16:34:51 2023 + * Thu Dec 21 18:12:49 2023 * Joe * * the main @@ -59,14 +59,20 @@ type HardOpts struct { // this function recurses into the specified root directory in order to load // every yaml file into memory -func c_recurse_data_dir(dir string, root string, lhost *HostList) { +// TODO - must rewrite this function entirely +func c_recurse_data_dir(dir string, root string, + lhost *HostList, ldirs *DirsList) { files, err := os.ReadDir(root + dir) if err != nil { c_die("could not read data directory", err) } for _, file := range files { if file.IsDir() == true { - c_recurse_data_dir(dir + file.Name() + "/", root, lhost) + var dir_node *DirsNode + dir_node.name = file.Name() + dir_node.parent = dont_know + ldirs.add_back(dir_node) + c_recurse_data_dir(dir + file.Name() + "/", root, lhost, ldirs) } else if filepath.Ext(file.Name()) == ".yml" { host := c_read_yaml_file(root + dir + file.Name()) if host == nil { @@ -82,6 +88,9 @@ func c_recurse_data_dir(dir string, root string, lhost *HostList) { func c_load_data_dir(dir string) (*HostList, *DirsList) { lhost := HostList{} ldirs := DirsList{} - c_recurse_data_dir("", dir + "/", &lhost) + var root_dir DirsNode + + ldirs.add_back(&root_dir) + c_recurse_data_dir("", dir + "/", &lhost, &ldirs) return &lhost, &ldirs } @@ -39,7 +39,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * hardflip: src/c_ldirs.go - * Thu Dec 21 14:03:40 2023 + * Thu Dec 21 18:06:00 2023 * Joe * * the directories linked list @@ -57,3 +57,18 @@ type DirsNode struct { type DirsList struct { head *DirsNode } + +// adds a directory node to the list +func (ldirs *DirsList) add_back(node *DirsNode) { + new_node := node + + if ldirs.head == nil { + ldirs.head = new_node + return + } + curr := ldirs.head + for curr.next != nil { + curr = curr.next + } + curr.next = new_node +} |