mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-12-27 08:12:32 +00:00
Use parent directory as working directory for project duplication and snapshots. Fixes https://github.com/GNS3/gns3-gui/issues/2909
This commit is contained in:
parent
dff035d957
commit
0390fef74d
@ -1020,7 +1020,16 @@ class Project:
|
|||||||
assert self._status != "closed"
|
assert self._status != "closed"
|
||||||
try:
|
try:
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
|
||||||
|
# use the parent directory of the project we are duplicating as a
|
||||||
|
# temporary directory to avoid no space left issues when '/tmp'
|
||||||
|
# is location on another partition.
|
||||||
|
if location:
|
||||||
|
working_dir = os.path.abspath(os.path.join(location, os.pardir))
|
||||||
|
else:
|
||||||
|
working_dir = os.path.abspath(os.path.join(self.path, os.pardir))
|
||||||
|
|
||||||
|
with tempfile.TemporaryDirectory(dir=working_dir) as tmpdir:
|
||||||
# Do not compress the exported project when duplicating
|
# Do not compress the exported project when duplicating
|
||||||
with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream:
|
with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream:
|
||||||
await export_project(zstream, self, tmpdir, keep_compute_id=True, allow_all_nodes=True, reset_mac_addresses=reset_mac_addresses)
|
await export_project(zstream, self, tmpdir, keep_compute_id=True, allow_all_nodes=True, reset_mac_addresses=reset_mac_addresses)
|
||||||
|
@ -95,7 +95,7 @@ class Snapshot:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
with tempfile.TemporaryDirectory(dir=snapshot_directory) as tmpdir:
|
||||||
# Do not compress the snapshots
|
# Do not compress the snapshots
|
||||||
with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream:
|
with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream:
|
||||||
await export_project(zstream, self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
await export_project(zstream, self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True)
|
||||||
|
@ -331,9 +331,11 @@ class ProjectHandler:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
# use the parent directory as a temporary working dir
|
||||||
|
working_dir = os.path.abspath(os.path.join(project.path, os.pardir))
|
||||||
|
with tempfile.TemporaryDirectory(dir=working_dir) as tmpdir:
|
||||||
with aiozipstream.ZipFile(compression=compression) as zstream:
|
with aiozipstream.ZipFile(compression=compression) as zstream:
|
||||||
await export_project(zstream, project, tmp_dir, include_snapshots=include_snapshots, include_images=include_images, reset_mac_addresses=reset_mac_addresses)
|
await export_project(zstream, project, tmpdir, include_snapshots=include_snapshots, include_images=include_images, reset_mac_addresses=reset_mac_addresses)
|
||||||
|
|
||||||
# We need to do that now because export could failed and raise an HTTP error
|
# We need to do that now because export could failed and raise an HTTP error
|
||||||
# that why response start need to be the later possible
|
# that why response start need to be the later possible
|
||||||
@ -380,7 +382,9 @@ class ProjectHandler:
|
|||||||
# It could be more optimal to stream this but it is not implemented in Python.
|
# It could be more optimal to stream this but it is not implemented in Python.
|
||||||
try:
|
try:
|
||||||
begin = time.time()
|
begin = time.time()
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
# use the parent directory as a temporary working dir
|
||||||
|
working_dir = os.path.abspath(os.path.join(path, os.pardir))
|
||||||
|
with tempfile.TemporaryDirectory(dir=working_dir) as tmpdir:
|
||||||
temp_project_path = os.path.join(tmpdir, "project.zip")
|
temp_project_path = os.path.join(tmpdir, "project.zip")
|
||||||
async with aiofiles.open(temp_project_path, 'wb') as f:
|
async with aiofiles.open(temp_project_path, 'wb') as f:
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user