mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-19 13:14:22 +01:00
Extract files during import_ctf
This commit is contained in:
@@ -85,7 +85,7 @@ class Config(object):
|
||||
The default destination is the CTFd/uploads folder. If you need Amazon S3 files
|
||||
you can use the CTFd S3 plugin: https://github.com/ColdHeat/CTFd-S3-plugin
|
||||
'''
|
||||
UPLOAD_FOLDER = os.path.normpath('uploads')
|
||||
UPLOAD_FOLDER = os.path.join(os.path.dirname(__file__), 'uploads')
|
||||
|
||||
|
||||
'''
|
||||
|
||||
@@ -790,3 +790,25 @@ def import_ctf(backup, segments=None, erase=False):
|
||||
table.insert(entry)
|
||||
else:
|
||||
continue
|
||||
|
||||
## Extracting files
|
||||
files = [f for f in backup.namelist() if f.startswith('uploads/')]
|
||||
upload_folder = app.config.get('UPLOAD_FOLDER')
|
||||
for f in files:
|
||||
filename = f.split(os.sep, 1)
|
||||
|
||||
if len(filename) < 2: ## just an empty uploads directory (e.g. uploads/)
|
||||
continue
|
||||
|
||||
filename = filename[1] ## Get the second entry in the list (the actual filename)
|
||||
full_path = os.path.join(upload_folder, filename)
|
||||
dirname = os.path.dirname(full_path)
|
||||
|
||||
## Create any parent directories for the file
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
|
||||
source = backup.open(f)
|
||||
target = file(full_path, "wb")
|
||||
with source, target:
|
||||
shutil.copyfileobj(source, target)
|
||||
Reference in New Issue
Block a user