aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolderpunk <solderpunk@sdf.org>2018-12-11 18:26:08 +0000
committerSolderpunk <solderpunk@sdf.org>2018-12-11 18:26:08 +0000
commitd572d931ffecfadeaa5a3cba5bd5c4c8eb8a691f (patch)
treebb66c9273f2d1daaf623dd05d5e62b2664c5bc54
parentDon't crash if a new user doesn't have a scanfile. (diff)
Don't accept empty or non-existent files as posts.
-rwxr-xr-xtelem.lua28
1 files changed, 24 insertions, 4 deletions
diff --git a/telem.lua b/telem.lua
index 0bfebe9..e1e9661 100755
--- a/telem.lua
+++ b/telem.lua
@@ -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()