Fix chal deletion (#241)

* improving get_config
* Fixing challenge deletion
* Puts challenge deletion under utils.delete_file
This commit is contained in:
Kevin Chung
2017-04-08 03:29:11 -04:00
committed by GitHub
parent b2fc5a6fcd
commit aa21a3c161
2 changed files with 4 additions and 6 deletions

View File

@@ -263,11 +263,9 @@ def admin_delete_chal():
Solves.query.filter_by(chalid=challenge.id).delete()
Keys.query.filter_by(chal=challenge.id).delete()
files = Files.query.filter_by(chal=challenge.id).all()
for f in files:
utils.delete_file(f.id)
Files.query.filter_by(chal=challenge.id).delete()
for file in files:
upload_folder = app.config['UPLOAD_FOLDER']
folder = os.path.dirname(os.path.join(os.path.normpath(app.root_path), upload_folder, file.location))
utils.rmdir(folder)
Tags.query.filter_by(chal=challenge.id).delete()
Challenges.query.filter_by(id=challenge.id).delete()
db.session.commit()

View File

@@ -349,8 +349,8 @@ def upload_file(file, chalid):
return True
def delete_file(filename):
f = Files.query.filter_by(id=filename).first_or_404()
def delete_file(file_id):
f = Files.query.filter_by(id=file_id).first_or_404()
upload_folder = os.path.join(app.root_path, app.config['UPLOAD_FOLDER'])
if os.path.exists(os.path.join(upload_folder, f.location)): # Some kind of os.path.isfile issue on Windows...
os.unlink(os.path.join(upload_folder, f.location))