[Libguestfs] [PATCH 3/8] builder: add functions to read XDG_CONFIG_DIRS and XDG_CONFIG_PATH

Pino Toscano ptoscano at redhat.com
Tue Feb 25 16:29:08 UTC 2014


---
 builder/paths.ml | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/builder/paths.ml b/builder/paths.ml
index 66e8922..e4f0c7b 100644
--- a/builder/paths.ml
+++ b/builder/paths.ml
@@ -24,3 +24,18 @@ let xdg_cache_home =
     try Some (Sys.getenv "HOME" // ".cache" // "virt-builder")
     with Not_found ->
       None (* no cache directory *)
+
+let xdg_config_home ~prog =
+  try Some (Sys.getenv "XDG_CONFIG_HOME" // prog)
+  with Not_found ->
+    try Some (Sys.getenv "HOME" // ".config" // prog)
+    with Not_found ->
+      None (* no config directory *)
+
+let xdg_config_dirs ~prog =
+  let dirs =
+    try Sys.getenv "XDG_CONFIG_DIRS"
+    with Not_found -> "/etc/xdg" in
+  let dirs = string_nsplit ":" dirs in
+  let dirs = List.filter (fun x -> x <> "") dirs in
+  List.map (fun x -> x // prog) dirs
-- 
1.8.3.1




More information about the Libguestfs mailing list