]> git.e2factory.org Git - e2factory.git/commitdiff
parse_server_location: improve doc, lock table, fix return errors
authorTobias Ulmer <tu@emlix.com>
Tue, 3 Dec 2013 18:19:27 +0000 (19:19 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
global/e2-fetch-project.lua
local/e2-new-source.lua

index 220f71475aff3db12c6202e7f13e9c1ba778e1db..4284e0fe5bfe023caa9feaf5ebcf3c65b6fd27c6 100644 (file)
@@ -2104,28 +2104,37 @@ function e2lib.parentdirs(path)
     return t
 end
 
-
---- parse a server:location string, taking a default server into account
+--- Parse a server:location string, taking a default server into account.
 -- @param serverloc string: the string to parse
--- @param default_server string: the default server name
--- @return a table with fields server and location, nil on error
--- @return nil, an error string on error
+-- @param default_server Default server name used when serverloc contains none.
+-- @return Locked server location table, false on error
+-- @return Error object on failure.
+-- @see server_location
 function e2lib.parse_server_location(serverloc, default_server)
     assert(type(serverloc) == 'string' and type(default_server) == 'string')
+
+    --- Server location table.
+    -- @table server_location
+    -- @field server Server name, defaults to default_server if not supplied.
+    -- @field location Path location relative to the server.
+    -- @see parse_server_location
     local sl = {}
+
     sl.server, sl.location = serverloc:match("(%S+):(%S+)")
     if not (sl.server and sl.location) then
         sl.location = serverloc:match("(%S+)")
         if not (sl.location and default_server) then
-            return nil, "can't parse location"
+            return false, err.new("can't parse location in %q", serverloc)
         end
         sl.server = default_server
     end
+
     if sl.location:match("[.][.]") or
         sl.location:match("^/") then
-        return nil, "invalid location"
+        return false, err.new("invalid location: %q", serverloc)
     end
-    return sl
+
+    return strict.lock(sl)
 end
 
 --- setup cache from the global server configuration
index 0c7e4d25667f62073e1f8f59d6e80a2fb4f1273f..98d803bc0cb5d9f45a4fb50719db7235d3e6071c 100644 (file)
@@ -75,7 +75,7 @@ local function e2_fetch_project(arg)
     end
 
     local sl, re = e2lib.parse_server_location(arguments[1],
-    e2lib.globals.default_projects_server)
+        e2lib.globals.default_projects_server)
     if not sl then
         return false, e:cat(re)
     end
index 9c10d82db7f81253162365b6780781c1cf29ddb3..a49ff58da1debb8f319d8a50431bd0466cab5951 100644 (file)
@@ -270,9 +270,9 @@ local function e2_new_source(arg)
         end
 
         local location = arguments[1]
-        local sl, e = e2lib.parse_server_location(location, info.default_files_server)
+        local sl, re = e2lib.parse_server_location(location, info.default_files_server)
         if not sl then
-            return false, e
+            return false, re
         end
         local server = sl.server
         local location = sl.location