return tartype
end
---- Read the first line from the given file and return it.
--- Beware that end of file is considered an error.
--- @param path Path to file (string).
--- @return The first line or false on error.
--- @return Error object on failure.
-function e2lib.read_line(path)
- local f, msg = io.open(path)
- if not f then
- return false, err.new("%s: %s", path, msg)
- end
- local l, msg = f:read("*l")
- f:close()
- if not l then
- if not msg then
- msg = "end of file"
- end
-
- return false, err.new("%s: %s", path, msg)
- end
- return l
-end
-
--- Use the global parameters from the global configuration.
-- @return True on success, false on error.
-- @return Error object on failure.
return leio.cloexec(something, set)
end
+
+--- Read the first line from file pointed to by filename. End of file is
+-- considered to be an error.
+-- @param filename File name.
+-- @return First line of text, up to but not including the new-line character.
+-- False on error.
+-- @return Error object on failure.
+function eio.file_read_line(filename)
+ local file, re, line, rc
+
+ file, re = eio.fopen(filename, "r")
+ if not file then
+ return false, re
+ end
+
+ line, re = eio.readline(file)
+ if not line then
+ eio.fclose(file)
+ return false, re
+ end
+
+ rc, re = eio.fclose(file)
+ if not rc then
+ return false, re
+ end
+
+ if line == "" then
+ return false, err.new("unexpected end of file in %q", filename)
+ end
+
+ if string.sub(line, -1) == "\n" then
+ line = string.sub(line, 1, -2)
+ end
+
+ return line
+end
+
return strict.lock(eio)
-- vim:sw=4:sts=4:et:
local generic_git = {}
local e2lib = require("e2lib")
+local eio = require("eio")
local cache = require("cache")
local url = require("url")
local tools = require("tools")
e:append("git config failed")
return nil, e
end
- local git_output = e2lib.read_line(tmpfile)
+ local git_output, re = eio.file_read_line(tmpfile)
if not git_output then
+ e:cat(re)
return nil, e:append("can't read git output from temporary file")
end
e2lib.rmtempfile(tmpfile)
local e2lib = require("e2lib")
local e2option = require("e2option")
+local eio = require("eio")
local generic_git = require("generic_git")
local cache = require("cache")
local err = require("err")
-- read the version from the first line
local version_file = string.format("%s/version", tmpdir)
- local line, re = e2lib.read_line(version_file)
+ local line, re = eio.file_read_line(version_file)
if not line then
return false, e:cat(re)
end
local e2lib = require("e2lib")
local e2option = require("e2option")
+local eio = require("eio")
local generic_git = require("generic_git")
local err = require("err")
local buildconfig = require("buildconfig")
return false, err.new("can't locate project root.")
end
- -- try to get project specific config file paht
- local config_file_config = string.format("%s/%s", root, e2lib.globals.e2config)
- local config_file = e2lib.read_line(config_file_config)
+ -- try to get project specific config file path
-- don't care if this succeeds, the parameter is optional.
+ local config_file_config = e2lib.join(root, e2lib.globals.e2config)
+ local config_file = eio.file_read_line(config_file_config)
local rc, e = e2lib.read_global_config(config_file)
if not rc then
end
-- read the version from the first line
- local line, re = e2lib.read_line(e2lib.globals.global_interface_version_file)
+ local line, re = eio.file_read_line(
+ e2lib.globals.global_interface_version_file)
if not line then
return false, e:cat(re)
end
extensions = {} -- empty list
end
- local s = e2lib.read_line(".e2/e2version")
+ local s, re = eio.file_read_line(".e2/e2version")
local branch, tag = s:match("(%S+) (%S+)")
if not branch or not tag then
- return false, e:append("cannot parse e2 version")
+ e:cat(re)
+ return false, e:cat(err.new("cannot parse e2 version"))
end
local ref
if tag == "^" then
local e2tool = {}
local e2lib = require("e2lib")
+local eio = require("eio")
local err = require("err")
local scm = require("scm")
local tools = require("tools")
-- @return an error object on failure
local function check_config_syntax_compat(info)
local e = err.new("checking configuration syntax compatibilitly failed")
- local l, re = e2lib.read_line(info.config_syntax_file)
+ local l, re = eio.file_read_line(info.config_syntax_file)
if not l then
return false, e:cat(re)
end
end
end
local s = [[
- Your configuration syntax is incompatible with this tool version.
- Please read the configuration Changelog, update your project configuration
- and finally insert the new configuration syntax version into %s
+Your configuration syntax is incompatible with this tool version.
+Please read the configuration Changelog, update your project configuration
+and finally insert the new configuration syntax version into %s
- Configuration syntax versions supported by this version of the tools are:
- ]]
+Configuration syntax versions supported by this version of the tools are:]]
e2lib.logf(2, s, info.config_syntax_file)
for _,m in ipairs(info.config_syntax_compat) do
- e2lib.logf(2, " %s", m)
+ e2lib.logf(2, "%s", m)
end
+ e2lib.logf(2, "Currently configured configuration syntax is: %q", l)
return false, e:append("configuration syntax mismatch")
end
e2lib.finish(1)
end
- -- try to get project specific config file paht
- local config_file_config = e2lib.join(info.root, e2lib.globals.e2config)
- local config_file = e2lib.read_line(config_file_config)
+ -- try to get project specific config file path
-- don't care if this succeeds, the parameter is optional.
+ local config_file_config = e2lib.join(info.root, e2lib.globals.e2config)
+ local config_file = eio.file_read_line(config_file_config)
local rc, re = e2lib.read_global_config(config_file)
if not rc then
-- read .e2/proj-location
info.project_location_config = e2lib.join(info.root, ".e2/project-location")
- local line, re = e2lib.read_line(info.project_location_config)
+ local line, re = eio.file_read_line(info.project_location_config)
if not line then
return false, e:cat(re)
end
-- read global interface version and check if this version of the local
-- tools supports the version used for the project
- local line, re = e2lib.read_line(e2lib.globals.global_interface_version_file)
+ local line, re = eio.file_read_line(e2lib.globals.global_interface_version_file)
if not line then
return false, e:cat(re)
end
return e2tool.dlist_recursive(info, info.project.default_results)
end
---- read hash file.
-local function read_hash_file(info, server, location)
- local e = err.new("error reading hash file")
- local cs = nil
- local cache_flags = { cache = true }
- local rc, re = info.cache:cache_file(server, location, cache_flags)
- if not rc then
- return nil, e:cat(re)
- end
- local path = info.cache:file_path(server, location, cache_flags)
- if path then
- cs = e2lib.read_line(path)
- if cs then
- return cs, nil
- end
- end
- return nil, e:append("can't open checksum file")
-end
-
--- hash a file
-- @param path string: path to a file
-- @return string the hash value, nil on error