]> git.e2factory.org Git - e2factory.git/commitdiff
Remove slashToDot() and export two replacements
authorTobias Ulmer <tu@emlix.com>
Tue, 19 Feb 2013 20:04:41 +0000 (21:04 +0100)
committerTobias Ulmer <tu@emlix.com>
Tue, 26 Feb 2013 18:07:15 +0000 (19:07 +0100)
Results/source names can now reliably be converted into a file system
path or into e2factory group notation using
e2tool.src_res_name_to_path() and e2tool.src_res_path_to_name()

Signed-off-by: Tobias Ulmer <tu@emlix.com>
local/e2tool.lua

index 8791d4252b6bda48e0d3726d136dec930c64a55f..cf7afb7d5b6fd0c61b8eccc07a6a2cbd7514608d 100644 (file)
@@ -937,9 +937,20 @@ function e2tool.verify_src_res_name_valid_chars(name)
     return true
 end
 
---- replaces all slashed in str with dots
-local function slashToDot(str)
-    return string.gsub(str,"/", ".")
+--- Convert source or result name, including groups, to a file system path.
+-- @param name Name of a src or res, with optional group notation (string).
+-- @return File system path equivalent of the input.
+function e2tool.src_res_name_to_path(name)
+    return name:gsub("%.", "/")
+end
+
+--- Convert file system path of a source or result, including sub-directories
+-- to group notation separated by dots.
+-- @param pathname File system path of a src or res, with optional
+-- sub-directories (string).
+-- @return Group dot notation equivalent of the input.
+function e2tool.src_res_path_to_name(pathname)
+    return pathname:gsub("/", ".")
 end
 
 --- load source config.
@@ -970,8 +981,8 @@ local function load_source_config(info)
             if not name and #list == 1 then
                 e2lib.warnf("WDEFAULT", "`name' attribute missing in source config.")
                 e2lib.warnf("WDEFAULT", " Defaulting to directory name")
-                item.data.name = slashToDot(src)
-                name = slashToDot(src)
+                item.data.name = e2tool.src_res_path_to_name(src)
+                name = item.data.name
             end
 
             if not name then
@@ -1098,8 +1109,8 @@ local function load_result_config(info)
                 return false, e
             end
 
-            item.data.name = slashToDot(res)
-            name = slashToDot(res)
+            item.data.name = e2tool.src_res_path_to_name(res)
+            name = item.data.name
 
             local rc, re = e2tool.verify_src_res_name_valid_chars(name)
             if not rc then