diff --git a/bin/tar.ml b/bin/tar.ml index 46f6a6b..609fd05 100644 --- a/bin/tar.ml +++ b/bin/tar.ml @@ -60,11 +60,17 @@ let find path tree = | _ -> failwith "cannot search non-directory" in aux (p, tree) +let add_child name node map = + match (NameMap.find_opt name map, node) with + | Some (InferredDirectory (children, _)), Directory (_, md) -> + NameMap.add name (Directory (children, md)) map + | _ -> NameMap.add name node map +(* TODO: add logic for links, device nodes, and replacing inferred directories *) let add_direct name node = function | InferredDirectory (map, md) -> - InferredDirectory ((NameMap.add name node map), md) + InferredDirectory ((add_child name node map), md) | Directory (map, md) -> - Directory ((NameMap.add name node map), md) + Directory ((add_child name node map), md) | _ -> Printf.printf "whatever the fuck %s" name; Directory (NameMap.empty, empty_dir_metadata)