summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElie Roux <elie.roux@telecom-bretagne.eu>2010-02-25 22:42:18 +0200
committerElie Roux <elie.roux@telecom-bretagne.eu>2010-02-25 22:42:18 +0200
commitdfeea3a714ef9050942748e1ea68e73c73bf59fb (patch)
treeba5f3504b4d3c8a1fbc1bda35d6b2cd103361780
parentb35abcf3c0caa9f8d098e635fbaf1f70b36d1b92 (diff)
downloadluaotfload-dfeea3a714ef9050942748e1ea68e73c73bf59fb.tar.gz
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...
-rw-r--r--luaotfload-fonts.lua31
1 files changed, 19 insertions, 12 deletions
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