From 8140eb174a9c5a16f818245a38d25b55cbc52a2e Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Thu, 12 Feb 2009 21:54:34 -0500 Subject: If filename exists, but cannot be read, do not open it; core/file_io.lua --- core/file_io.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'core') 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() -- cgit v1.2.3