diff options
author | 2009-02-12 21:54:34 -0500 | |
---|---|---|
committer | 2009-02-12 21:54:34 -0500 | |
commit | 8140eb174a9c5a16f818245a38d25b55cbc52a2e (patch) | |
tree | 1c0fca60b15380afd9b8d5fcc536a1dd1af5da39 /core/file_io.lua | |
parent | 282fba45a5782e2dd9103fc95e78067faaa5a4cc (diff) | |
download | textadept-8140eb174a9c5a16f818245a38d25b55cbc52a2e.tar.gz textadept-8140eb174a9c5a16f818245a38d25b55cbc52a2e.zip |
If filename exists, but cannot be read, do not open it; core/file_io.lua
Diffstat (limited to 'core/file_io.lua')
-rw-r--r-- | core/file_io.lua | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/core/file_io.lua b/core/file_io.lua index 8e487930..d65c5c2f 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -26,16 +26,20 @@ local function open_helper(filename) for index, buffer in ipairs(textadept.buffers) do if filename == buffer.filename then view:goto_buffer(index) return end end - local buffer = textadept.new_buffer() - local f, err = io.open(filename, 'rb') + local text + local f = io.open(filename, 'rb') if f then - local text = f:read('*all') + text = f:read('*all') + f:close() + if not text then return end -- filename exists, but can't read it + end + local buffer = textadept.new_buffer() + if text then local chunk = #text > 65536 and text:sub(1, 65536) or text if chunk:find('\0') then buffer.code_page = 0 end -- binary file; no UTF-8 buffer:add_text(text, #text) buffer:goto_pos(0) buffer:empty_undo_buffer() - f:close() end buffer.filename = filename buffer:set_save_point() |