Skip to content

Commit

Permalink
report open error properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaurens authored and josephwright committed Jul 3, 2024
1 parent 48ab867 commit 11829b2
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 30 deletions.
14 changes: 10 additions & 4 deletions build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ function docinit_hook()
local insert = table.insert
local open = io.open

local f = open("README.md","rb")
local readme = f:read("*all")
---@type file*?
local f = assert(open("README.md","rb"))
---@cast f file*
local readme = f:read("a")
f:close()
f = nil

local date_start,date_end = find(readme,"%d%d%d%d%p%d%d%p%d%d")

local man_t = {}
Expand All @@ -121,9 +126,10 @@ function docinit_hook()
insert(man_t,overview)

local cmd = "texlua ./" .. module .. ".lua --help"
local f = assert(io.popen(cmd,"r"))
local help_text = assert(f:read("*a"))
f = assert(io.popen(cmd,"r"))
local help_text = assert(f:read("a"))
f:close()
f = nil

insert(man_t,(help_text:gsub("\nUsage.*names>]\n\n","")
:gsub("Valid targets",".SH COMMANDS\nValid targets")
Expand Down
18 changes: 9 additions & 9 deletions l3build-check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ function checkinit_hook() return 0 end

local function rewrite(source,result,processor,...)
local file = assert(open(source,"rb"))
local content = gsub(file:read("*all") .. "\n","\r\n","\n")
local content = gsub(file:read("a") .. "\n","\r\n","\n")
close(file)
local new_content = processor(content,...)
local newfile = open(result,"w")
local newfile = assert(open(result,"w"))
output(newfile)
write(new_content)
close(newfile)
Expand Down Expand Up @@ -919,7 +919,7 @@ local function showsavecommands(failurelist)
end
end
print(" To regenerate the test files, run\n")
local f = open(testdir .. "/.savecommands", "w")
local f = assert(open(testdir .. "/.savecommands", "w"))
for _, cmds in pairs(savecmds) do
print(" " .. cmds)
f:write(cmds, "\n")
Expand Down Expand Up @@ -1089,9 +1089,9 @@ function showfailedlog(name)
for _,i in ipairs(ordered_filelist(testdir, name..".log")) do
print(" - " .. testdir .. "/" .. i)
print("")
local f = open(testdir .. "/" .. i,"r")
local content = f:read("*all")
close(f)
local f = assert(open(testdir .. "/" .. i,"r"))
local content = f:read("a")
f:close()
print("-----------------------------------------------------------------------------------")
print(content)
print("-----------------------------------------------------------------------------------")
Expand All @@ -1103,9 +1103,9 @@ function showfaileddiff()
for _,i in ipairs(ordered_filelist(testdir, "*" .. os_diffext)) do
print(" - " .. testdir .. "/" .. i)
print("")
local f = open(testdir .. "/" .. i,"r")
local content = f:read("*all")
close(f)
local f = assert(open(testdir .. "/" .. i,"r"))
local content = f:read("a")
f:close()
print("-----------------------------------------------------------------------------------")
print(content)
print("-----------------------------------------------------------------------------------")
Expand Down
2 changes: 1 addition & 1 deletion l3build-ctan.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function ctan()
options["engine"] = nil
local function dirzip(dir, zipname)
zipname = zipname .. ".zip"
local zip = newzip(dir .. '/' .. zipname)
local zip = assert(newzip(dir .. '/' .. zipname))
local function tab_to_check(table)
local patterns = {}
for n,i in ipairs(table) do
Expand Down
2 changes: 1 addition & 1 deletion l3build-manifest-setup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ end
-- From the first match of a pattern in a file:
manifest_extract_filedesc = function(filehandle)
local all_file = filehandle:read("*all")
local all_file = filehandle:read("a")
local matchstr = "\\section{(.-)}"
filedesc = string.match(all_file,matchstr)
Expand Down
5 changes: 3 additions & 2 deletions l3build-manifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ manifest_build_init = function(entry)

end

local open = io.open

manifest_build_file = function(entry,this_file)

Expand All @@ -173,7 +174,7 @@ manifest_build_file = function(entry,this_file)

if not(entry.skipfiledescription) then

local ff = assert(io.open(entry.dir .. "/" .. this_file, "r"))
local ff = assert(open(entry.dir .. "/" .. this_file, "r"))
this_descr = manifest_extract_filedesc(ff,this_file)
ff:close()

Expand All @@ -197,7 +198,7 @@ end

manifest_write = function(manifest_entries)

local f = assert(io.open(manifestfile, "w"))
local f = assert(open(manifestfile, "w"))
manifest_write_opening(f)

for ii,vv in ipairs(manifest_entries) do
Expand Down
5 changes: 4 additions & 1 deletion l3build-tagging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ end
local function update_file_tag(file,tagname,tagdate)
local filename = basename(file)
print("Tagging ".. filename)
---@type file*?
local f = assert(open(file,"rb"))
local content = f:read("*all")
---@cast f file*
local content = f:read("a")
f:close()
f = nil
-- Deal with Unix/Windows line endings
content = gsub(content .. (match(content,"\n$") and "" or "\n"),
"\r\n", "\n")
Expand Down
5 changes: 3 additions & 2 deletions l3build-unpack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ function bundleunpack(sourcedirs, sources)
return errorlevel
end
end
local popen = io.popen
for _,i in ipairs(unpackfiles) do
for _,p in ipairs(tree(unpackdir, i)) do
local path, name = splitpath(p.src)
local localdir = abspath(localdir)
local success = io.popen(
local success = assert(popen(
"cd " .. unpackdir .. "/" .. path .. os_concat ..
os_setenv .. " TEXINPUTS=." .. os_pathsep
.. localdir .. (unpacksearch and os_pathsep or "") ..
Expand All @@ -84,7 +85,7 @@ function bundleunpack(sourcedirs, sources)
unpackexe .. " " .. unpackopts .. " " .. name
.. (options["quiet"] and (" > " .. os_null) or ""),
"w"
):write(string.rep("y\n", 300)):close()
):write(string.rep("y\n", 300))):close()
if not success then
return 1
end
Expand Down
19 changes: 11 additions & 8 deletions l3build-upload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ function upload(tagnames)

-- Get data from command line if appropriate
if options["file"] then
local f = open(options["file"],"r")
uploadconfig.announcement = assert(f:read('*a'))
close(f)
local f = assert(open(options["file"],"r"))
uploadconfig.announcement = assert(f:read('a'))
f:close()
end
uploadconfig.announcement = options["message"] or uploadconfig.announcement or file_contents(uploadconfig.announcement_file)
uploadconfig.email = options["email"] or uploadconfig.email
Expand Down Expand Up @@ -139,10 +139,13 @@ function upload(tagnames)

-- curl file version
local curloptfile = uploadconfig.curlopt_file or (ctanzip .. ".curlopt")
local curlopt=open(curloptfile,"w")
---@type file*?
local curlopt=assert(open(curloptfile,"w"))
---@cast curlopt file*
output(curlopt)
write(ctan_post)
close(curlopt)
curlopt:close()
curlopt = nil

ctan_post=curlexe .. " --config " .. curloptfile

Expand Down Expand Up @@ -376,12 +379,12 @@ end
-- if filename is non nil and file readable return contents otherwise nil
function file_contents (filename)
if filename ~= nil then
local f= open(filename,"r")
local f= assert(open(filename,"r"))
if f==nil then
return nil
else
local s = f:read("*all")
close(f)
local s = f:read("a")
f:close()
return s
end
else
Expand Down
2 changes: 1 addition & 1 deletion l3build-zip.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ local meta = {__index = {
}}

return function(filename)
local f, msg = open(filename, 'wb')
local f, msg = open(filename, 'wb') -- closed just above
if not f then return f, msg end
return setmetatable({
f = f,
Expand Down
2 changes: 1 addition & 1 deletion l3build.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -2144,7 +2144,7 @@
% \begin{verbatim}
% manifest_extract_filedesc = function(filehandle,filename)
%
% local all_file = filehandle:read("*all")
% local all_file = filehandle:read("a")
% local matchstr = "\\section{(.-)}"
%
% filedesc = string.match(all_file,matchstr)
Expand Down

0 comments on commit 11829b2

Please sign in to comment.