return t
end
---- write a string to a file
--- @param file string: filename
--- @param data string: data
--- @return bool
--- @return nil, or an error string
-function e2lib.write_file(file, data)
- local f, msg = io.open(file, "w")
- if not f then
- return false, string.format("open failed: %s", msg)
- end
- local rc, msg = f:write(data)
- f:close()
- if not rc then
- return false, string.format("write failed: %s", msg)
- end
- return true, nil
-end
-
--- parse a server:location string, taking a default server into account
-- @param serverloc string: the string to parse
return line
end
+--- Create or truncate a file pointed to by filename, and fill it with data.
+-- @param filename File name.
+-- @param data String of data, may contain embedded zeros.
+-- @return True on success, false on error.
+-- @return Error object on failure.
+function eio.file_write(filename, data)
+ local rc, re, file
+
+ file, re = eio.fopen(filename, "w")
+ if not file then
+ return false, re
+ end
+
+ rc, re = eio.fwrite(file, data)
+ if not rc then
+ return false, re
+ end
+
+ rc, re = eio.fclose(file)
+ if not rc then
+ return false, re
+ end
+
+ return true
+end
+
return strict.lock(eio)
-- vim:sw=4:sts=4:et:
local e, rc, re, file, out
e = err.new("writing extensions config: %s", e2lib.globals.extension_config)
- file, re = eio.fopen(e2lib.globals.extension_config, "w")
- if not file then
- return false, e:cat(re)
- end
out = "extensions {\n"
for _,ex in ipairs(extensions) do
end
out = out .. "}\n"
- rc, re = eio.fwrite(file, out)
- if not rc then
- return false, e:cat(re)
- end
-
- rc, re = eio.fclose(file)
+ rc, re = eio.file_write(e2lib.globals.extension_config, out)
if not rc then
return false, e:cat(re)
end
if not rc then
return false, e:cat(re)
end
- rc, re = e2lib.write_file(f.filename, f.content)
+ rc, re = eio.file_write(f.filename, f.content)
if not rc then
return false, e:cat(re)
end
if not rc then
return false, e:cat(re)
end
- rc, re = e2lib.write_file(f.filename, f.content)
+ rc, re = eio.file_write(f.filename, f.content)
if not rc then
return false, e:cat(re)
end
-- write project location file
local file = ".e2/project-location"
local data = string.format("%s\n", p.location)
- local rc, re = e2lib.write_file(file, data)
+ rc, re = eio.file_write(file, data)
if not rc then
return false, e:cat(re)
end
-- write version file
- local rc, re = e2lib.write_file(e2lib.globals.global_interface_version_file,
- string.format("%d\n", v))
+ rc, re = eio.file_write(e2lib.globals.global_interface_version_file,
+ string.format("%d\n", v))
+ if not rc then
+ return false, e:cat(re)
+ end
-- call e2-install-e2
local e2_install_e2 = string.format("%s %s/e2-install-e2",
"%s/%s.sha1", destdir,
e2lib.basename(file.location))
local filename = e2lib.basename(file.location)
- rc, re = e2lib.write_file(checksum_file,
+ rc, re = eio.file_write(checksum_file,
string.format("%s %s", file.sha1, filename))
if not rc then
return false, e:cat(re)
end
local tsorted_results_string = table.concat(tsorted_results, "\n")
local resultlist = e2lib.join(destdir, "resultlist")
- rc, re = e2lib.write_file(resultlist, tsorted_results_string .. "\n")
+ rc, re = eio.file_write(resultlist, tsorted_results_string .. "\n")
if not rc then
return false, e:cat(re)
end
local cvs = {}
local e2lib = require("e2lib")
+local eio = require("eio")
local scm = require("scm")
local hash = require("hash")
local url = require("url")
if not rc then
return false, e:cat(re)
end
- rc, re = e2lib.write_file(fname, licence_list)
+ rc, re = eio.file_write(fname, licence_list)
if not rc then
return false, e:cat(re)
end
local err = require("err")
local e2lib = require("e2lib")
local e2tool = require("e2tool")
+local eio = require("eio")
local strict = require("strict")
local tools = require("tools")
if file.sha1 then
local filename = e2lib.basename(file.location)
local checksum_file = string.format("%s/%s.sha1",
- destdir, filename)
- rc, re = e2lib.write_file(checksum_file,
- string.format("%s %s", file.sha1, filename))
+ destdir, filename)
+ rc, re = eio.file_write(checksum_file,
+ string.format("%s %s", file.sha1, filename))
if not rc then
return false, e:cat(re)
end
if not rc then
return false, e:cat(re)
end
- rc, re = e2lib.write_file(fname, licence_list)
+ rc, re = eio.file_write(fname, licence_list)
if not rc then
return false, e:cat(re)
end
local e2option = require("e2option")
local e2lib = require("e2lib")
local e2tool = require("e2tool")
+local eio = require("eio")
local strict = require("strict")
local tools = require("tools")
if not rc then
return false, e:cat(re)
end
- rc, re = e2lib.write_file(fname, licence_list)
+ rc, re = eio.file_write(fname, licence_list)
if not rc then
return false, e:cat(re)
end
local tools = require("tools")
local err = require("err")
local e2lib = require("e2lib")
+local eio = require("eio")
local strict = require("strict")
plugin_descriptor = {
if not rc then
return false, e:cat(re)
end
- rc, re = e2lib.write_file(fname, licence_list)
+ rc, re = eio.file_write(fname, licence_list)
if not rc then
return false, e:cat(re)
end