mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-17 17:24:51 +02:00
Do not tweak zstd compression params
This commit is contained in:
parent
162af5bb7a
commit
c98a10dcfd
@ -16,7 +16,6 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
import json
|
import json
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiofiles
|
import aiofiles
|
||||||
|
@ -20,10 +20,10 @@ import sys
|
|||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
import shutil
|
import shutil
|
||||||
import zipfile
|
|
||||||
import aiofiles
|
import aiofiles
|
||||||
import itertools
|
import itertools
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import gns3server.utils.zipfile_zstd as zipfile_zstd
|
||||||
|
|
||||||
from .controller_error import ControllerError
|
from .controller_error import ControllerError
|
||||||
from .topology import load_topology
|
from .topology import load_topology
|
||||||
@ -60,9 +60,9 @@ async def import_project(controller, project_id, stream, location=None, name=Non
|
|||||||
raise ControllerError("The destination path should not contain .gns3")
|
raise ControllerError("The destination path should not contain .gns3")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(stream) as zip_file:
|
with zipfile_zstd.ZipFile(stream) as zip_file:
|
||||||
project_file = zip_file.read("project.gns3").decode()
|
project_file = zip_file.read("project.gns3").decode()
|
||||||
except zipfile.BadZipFile:
|
except zipfile_zstd.BadZipFile:
|
||||||
raise ControllerError("Cannot import project, not a GNS3 project (invalid zip)")
|
raise ControllerError("Cannot import project, not a GNS3 project (invalid zip)")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ControllerError("Cannot import project, project.gns3 file could not be found")
|
raise ControllerError("Cannot import project, project.gns3 file could not be found")
|
||||||
@ -92,9 +92,9 @@ async def import_project(controller, project_id, stream, location=None, name=Non
|
|||||||
raise ControllerError("The project name contain non supported or invalid characters")
|
raise ControllerError("The project name contain non supported or invalid characters")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with zipfile.ZipFile(stream) as zip_file:
|
with zipfile_zstd.ZipFile(stream) as zip_file:
|
||||||
await wait_run_in_executor(zip_file.extractall, path)
|
await wait_run_in_executor(zip_file.extractall, path)
|
||||||
except zipfile.BadZipFile:
|
except zipfile_zstd.BadZipFile:
|
||||||
raise ControllerError("Cannot extract files from GNS3 project (invalid zip)")
|
raise ControllerError("Cannot extract files from GNS3 project (invalid zip)")
|
||||||
|
|
||||||
topology = load_topology(os.path.join(path, "project.gns3"))
|
topology = load_topology(os.path.join(path, "project.gns3"))
|
||||||
@ -264,11 +264,11 @@ async def _import_snapshots(snapshots_path, project_name, project_id):
|
|||||||
# extract everything to a temporary directory
|
# extract everything to a temporary directory
|
||||||
try:
|
try:
|
||||||
with open(snapshot_path, "rb") as f:
|
with open(snapshot_path, "rb") as f:
|
||||||
with zipfile.ZipFile(f) as zip_file:
|
with zipfile_zstd.ZipFile(f) as zip_file:
|
||||||
await wait_run_in_executor(zip_file.extractall, tmpdir)
|
await wait_run_in_executor(zip_file.extractall, tmpdir)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
raise ControllerError(f"Cannot open snapshot '{os.path.basename(snapshot)}': {e}")
|
raise ControllerError(f"Cannot open snapshot '{os.path.basename(snapshot)}': {e}")
|
||||||
except zipfile.BadZipFile:
|
except zipfile_zstd.BadZipFile:
|
||||||
raise ControllerError(
|
raise ControllerError(
|
||||||
f"Cannot extract files from snapshot '{os.path.basename(snapshot)}': not a GNS3 project (invalid zip)"
|
f"Cannot extract files from snapshot '{os.path.basename(snapshot)}': not a GNS3 project (invalid zip)"
|
||||||
)
|
)
|
||||||
@ -294,7 +294,7 @@ async def _import_snapshots(snapshots_path, project_name, project_id):
|
|||||||
|
|
||||||
# write everything back to the original snapshot file
|
# write everything back to the original snapshot file
|
||||||
try:
|
try:
|
||||||
with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream:
|
with aiozipstream.ZipFile(compression=zipfile_zstd.ZIP_STORED) as zstream:
|
||||||
for root, dirs, files in os.walk(tmpdir, topdown=True, followlinks=False):
|
for root, dirs, files in os.walk(tmpdir, topdown=True, followlinks=False):
|
||||||
for file in files:
|
for file in files:
|
||||||
path = os.path.join(root, file)
|
path = os.path.join(root, file)
|
||||||
|
@ -71,8 +71,9 @@ def _get_compressor(compress_type, compresslevel=None):
|
|||||||
elif compress_type == ZIP_ZSTANDARD:
|
elif compress_type == ZIP_ZSTANDARD:
|
||||||
import zstandard as zstd
|
import zstandard as zstd
|
||||||
if compresslevel is not None:
|
if compresslevel is not None:
|
||||||
params = zstd.ZstdCompressionParameters.from_level(compresslevel, threads=-1, enable_ldm=True, window_log=31)
|
#params = zstd.ZstdCompressionParameters.from_level(compresslevel, threads=-1, enable_ldm=True, window_log=31)
|
||||||
return zstd.ZstdCompressor(compression_params=params).compressobj()
|
#return zstd.ZstdCompressor(compression_params=params).compressobj()
|
||||||
|
return zstd.ZstdCompressor(level=compresslevel).compressobj()
|
||||||
return zstd.ZstdCompressor().compressobj()
|
return zstd.ZstdCompressor().compressobj()
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user