(* repository.ml - Don Yang (uguu.org) 05/20/06 *) (* Root directory name *) let repository_root = "chii_repository";; (* Changelog name *) let changelog = "changelog";; (* Find location of existing repository, return empty string if not found *) let rec locate_recurse path = try let r = String.rindex path Path.separator in let parent_dir = String.sub path 0 r in let repository_path = parent_dir ^ Path.separator_str ^ repository_root in if Sys.file_exists repository_path then repository_path else locate_recurse parent_dir with Not_found -> "";; let locate () = locate_recurse (Path.normalize (Sys.getcwd()));; (* Create repository if it doesn't exist already. Return location of existing/created repository. *) let create () = let repository_path = locate() in if repository_path <> "" then repository_path else let cwd = Path.normalize (Sys.getcwd()) in try let r = String.rindex cwd Path.separator in let repository_path = (String.sub cwd 0 r) ^ Path.separator_str ^ repository_root in Unix.mkdir repository_path 0o755; repository_path with Not_found -> failwith "Can not create repository at root directory";; (* Get root of current directory *) let rec current_root_recurse path = try let r = String.rindex path Path.separator in let parent = String.sub path 0 r in if Sys.file_exists (parent ^ Path.separator_str ^ repository_root) then path else current_root_recurse parent with Not_found -> "";; let current_root () = current_root_recurse (Path.normalize (Sys.getcwd()));;