From 8d2a8654364da59a5592cfdac251d2a128d8624e Mon Sep 17 00:00:00 2001 From: JanB Date: Sun, 17 Apr 2016 17:42:22 +0200 Subject: [PATCH] Catch file permission errors when uploading PDF --- cps/web.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cps/web.py b/cps/web.py index 22831054..28512c23 100755 --- a/cps/web.py +++ b/cps/web.py @@ -861,8 +861,16 @@ def upload(): filepath = config.DB_ROOT + "/" + author_dir + "/" + title_dir saved_filename = filepath + "/" + data_name + fileextension if not os.path.exists(filepath): - os.makedirs(filepath) - file.save(saved_filename) + try: + os.makedirs(filepath) + except OSError: + flash("Failed to create path %s (Permission denied)." % filepath, category="error") + return redirect(url_for('index')) + try: + file.save(saved_filename) + except OSError: + flash("Failed to store file %s (Permission denied)." % saved_filename, category="error") + return redirect(url_for('index')) file_size = os.path.getsize(saved_filename) has_cover = 0 if fileextension.upper() == ".PDF":