From dfeea3a714ef9050942748e1ea68e73c73bf59fb Mon Sep 17 00:00:00 2001 From: Elie Roux Date: Thu, 25 Feb 2010 22:42:18 +0200 Subject: Actually working checks for writability Now we scan the fonts only if we can write in the final file. There is currently (if I understand correctly) no clean way to check if a folder is writable or not in Lua: lfs.attributes will give you the string returned by ls -l, but there is no simple way to know if we can actually write, as we don't know if we are the owner, or if we have access to the group... --- luaotfload-fonts.lua | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'luaotfload-fonts.lua') diff --git a/luaotfload-fonts.lua b/luaotfload-fonts.lua index f8fdb9e..d9b01f2 100644 --- a/luaotfload-fonts.lua +++ b/luaotfload-fonts.lua @@ -307,23 +307,30 @@ local function generate() families = { }, version = luaotfload.fonts.version, } - -- we save the scanned fonts in a variable in order for scan_os_fonts not - -- to rescan them - local scanned_fonts = scan_texmf_tree(fnames) - scan_os_fonts (fnames, scanned_fonts) - log(1, "%s fonts in %s families saved in the database", #fnames.mappings, #table.keys(fnames.families)) local savepath = luaotfload.fonts.directory - if not file.isreadable(savepath) then + if not lfs.isdir(savepath) then log(1, "Creating directory %s", savepath) lfs.mkdir(savepath) + if not lfs.isdir(savepath) then + texio.write_nl(string.format("Error: cannot create directory '%s', exiting.\n", savepath)) + os.exit(1) + end end - if not file.iswritable(savepath) then - log(1, "Error: cannot write in directory %s\n", savepath) - else - savepath = savepath .. luaotfload.fonts.basename - io.savedata(savepath, table.serialize(fnames, true)) - log(1, "Saved font names database in %s\n", savepath) + savepath = savepath .. luaotfload.fonts.basename + local fh = io.open(savepath, 'wb') + if not fh then + texio.write_nl(string.format("Error: cannot write file '%s', exiting.\n", savepath)) + os.exit(1) end + fh:close() + -- we save the scanned fonts in a variable in order for scan_os_fonts + -- not to rescan them + local scanned_fonts = scan_texmf_tree(fnames) + scan_os_fonts (fnames, scanned_fonts) + log(1, "%s fonts in %s families saved in the database", + #fnames.mappings, #table.keys(fnames.families)) + io.savedata(savepath, table.serialize(fnames, true)) + log(1, "Saved font names database in %s\n", savepath) end luaotfload.fonts.scan = scan_dir -- cgit v1.2.3