diff options
author | Solderpunk <solderpunk@sdf.org> | 2018-12-11 18:26:08 +0000 |
---|---|---|
committer | Solderpunk <solderpunk@sdf.org> | 2018-12-11 18:26:08 +0000 |
commit | d572d931ffecfadeaa5a3cba5bd5c4c8eb8a691f (patch) | |
tree | bb66c9273f2d1daaf623dd05d5e62b2664c5bc54 /telem.lua | |
parent | Don't crash if a new user doesn't have a scanfile. (diff) |
Don't accept empty or non-existent files as posts.
Diffstat (limited to 'telem.lua')
-rwxr-xr-x | telem.lua | 28 |
1 files changed, 24 insertions, 4 deletions
@@ -290,6 +290,17 @@ function do_messages() save_scan_times() end +function create_post() + -- This is used by both do_new and do_reply + -- Launch editor to save post in temporary file + local filename = os.tmpname() + os.execute(_EDITOR .. " " .. filename) + -- Check that file exists and is not empty + if not path.exists(filename) then return nil end + if lfs.attributes(filename).size == 0 then return nil end + return filename +end + function do_new() if not check_at_board() then return end -- Get subject for new thread @@ -303,8 +314,11 @@ function do_new() return end -- Save body of post to temp file - local filename = os.tmpname() - os.execute(_EDITOR .. " " .. filename) + local filename = create_post() + if not filename then + print("Post cancelled.") + return + end -- TODO: show and confirm -- Make thread dir local timestamp = tostring(os.time()) @@ -374,8 +388,13 @@ function do_type_prev() end function do_type_reply() - local filename = os.tmpname() - os.execute(_EDITOR .. " " .. filename) + -- Read reply body into temp file + local filename = create_post() + if not filename then + print("Empty file, reply cancelled.") + return + end + -- Move temp file to correct location and set permissions local timestamp = tostring(os.time()) local newfilename = timestamp .. "-" .. username local newpath = path.join(current_thread.directory, newfilename) @@ -384,6 +403,7 @@ function do_type_reply() print(str) end os.execute("chmod og+r " .. newpath) + -- Update state and show reply current_thread_posts = get_posts(current_thread) current_post_index = #current_thread_posts do_type_show_post() |