From 5b7fc88b9b8ece62a1ee5fa32164780abb442a3e Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Thu, 15 Oct 2015 01:31:31 -0700 Subject: pyblog: do not overwrite existing file when creating new post Fixes #7. --- pyblog | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pyblog') diff --git a/pyblog b/pyblog index c32464e2..593dd678 100755 --- a/pyblog +++ b/pyblog @@ -833,6 +833,10 @@ def new_post(title): if os.path.exists(POSTSDIR): os.remove(POSTSDIR) os.mkdir(POSTSDIR, mode=0o755) + if os.path.exists(fullpath): + sys.stderr.write("%serror: '%s' already exists, please pick a different title%s\n" % + (RED, fullpath, RESET)) + return 1 with open(fullpath, 'w', encoding='utf-8') as newpost: newpost.write("---\n") newpost.write('title: "%s"\n' % title) -- cgit v1.2.1