Better handle failure to open output file

This commit is contained in:
Marcel Krüger 2020-07-12 19:30:16 +02:00
parent d27e19a251
commit 5df4d5dd84

View File

@ -165,7 +165,11 @@ local pdfmeta = {
} }
pdfmeta.__index = pdfmeta pdfmeta.__index = pdfmeta
local function open(filename) local function open(filename)
local file = io.open(filename, 'wb') local file, msg = io.open(filename, 'wb')
if not file then
tex.error('Unable to open output file', string.format("Opening the output file %q failed. According to your system, the reason is: %q. If you continue, all output will be discarded.", filename, msg))
file = assert(io.tmpfile())
end
file:write"%PDF-X.X\n%\xC1\xAC\xC1\xB4\n" file:write"%PDF-X.X\n%\xC1\xAC\xC1\xB4\n"
return setmetatable({file = file, version = '1.7', [0] = 0, pages = {}, objstream = {}}, pdfmeta) return setmetatable({file = file, version = '1.7', [0] = 0, pages = {}, objstream = {}}, pdfmeta)
end end