Merge branch 'maintenance' into devel
This commit is contained in:
commit
c76fee7804
9 files changed
+31
-55
No files matched your search
@@ -4,7 +4,6 @@ __copyright__ = "Copyright (C) 2015 The OctoPrint Project - Released under terms
|
||||
|
||||
import logging
|
||||
import os
|
||||
import tarfile
|
||||
import zipfile
|
||||
from collections import defaultdict
|
||||
|
||||
@@ -141,12 +140,10 @@ def uploadLanguagePack():
|
||||
|
||||
target_path = settings().getBaseFolder("translations")
|
||||
|
||||
if tarfile.is_tarfile(upload_path):
|
||||
_unpack_uploaded_tarball(upload_path, target_path)
|
||||
elif zipfile.is_zipfile(upload_path):
|
||||
if zipfile.is_zipfile(upload_path):
|
||||
_unpack_uploaded_zipfile(upload_path, target_path)
|
||||
else:
|
||||
abort(400, description="Neither zip file nor tarball included")
|
||||
abort(400, description="No zip file included")
|
||||
|
||||
return getInstalledLanguagePacks()
|
||||
|
||||
@@ -181,16 +178,6 @@ def _unpack_uploaded_zipfile(path, target):
|
||||
zip.extractall(target)
|
||||
|
||||
|
||||
def _unpack_uploaded_tarball(path, target):
|
||||
with tarfile.open(path, "r") as tar:
|
||||
# sanity check
|
||||
for info in tar.getmembers():
|
||||
_validate_tar_info(info, target)
|
||||
|
||||
# unpack everything
|
||||
tar.extractall(target)
|
||||
|
||||
|
||||
def _validate_archive_name(name, target):
|
||||
if not os.path.abspath(os.path.join(target, name)).startswith(target + os.path.sep):
|
||||
raise InvalidLanguagePack(f"Provided language pack contains invalid name {name}")
|
||||
@@ -200,11 +187,5 @@ def _validate_zip_info(info, target):
|
||||
_validate_archive_name(info.filename, target)
|
||||
|
||||
|
||||
def _validate_tar_info(info, target):
|
||||
_validate_archive_name(info.name, target)
|
||||
if not (info.isfile() or info.isdir()):
|
||||
raise InvalidLanguagePack("Provided language pack contains invalid file type")
|
||||
|
||||
|
||||
class InvalidLanguagePack(Exception):
|
||||
pass
|
||||
Reference in new issue
Block a user