mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 00:08:11 +00:00
Update temporary status if project change location
This avoid race condition during file move.
This commit is contained in:
parent
8367a9eb30
commit
dae48b2de4
@ -114,6 +114,7 @@ class Project:
|
|||||||
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modifiy the project directory location")
|
raise aiohttp.web.HTTPForbidden(text="You are not allowed to modifiy the project directory location")
|
||||||
|
|
||||||
self._path = path
|
self._path = path
|
||||||
|
self._update_temporary_file()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def vms(self):
|
def vms(self):
|
||||||
@ -132,6 +133,13 @@ class Project:
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._temporary = temporary
|
self._temporary = temporary
|
||||||
|
self._update_temporary_file()
|
||||||
|
|
||||||
|
def _update_temporary_file(self):
|
||||||
|
"""
|
||||||
|
Update the .gns3_temporary file in order to reflect current
|
||||||
|
project status.
|
||||||
|
"""
|
||||||
|
|
||||||
if self._temporary:
|
if self._temporary:
|
||||||
try:
|
try:
|
||||||
|
@ -53,21 +53,37 @@ def test_path(tmpdir):
|
|||||||
p = Project(location=str(tmpdir))
|
p = Project(location=str(tmpdir))
|
||||||
assert p.path == os.path.join(str(tmpdir), p.id)
|
assert p.path == os.path.join(str(tmpdir), p.id)
|
||||||
assert os.path.exists(os.path.join(str(tmpdir), p.id))
|
assert os.path.exists(os.path.join(str(tmpdir), p.id))
|
||||||
assert not os.path.exists(os.path.join(p.path, '.gns3_temporary'))
|
assert not os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_changing_path_temporary_flag(tmpdir):
|
||||||
|
|
||||||
|
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
|
||||||
|
p = Project(temporary=True)
|
||||||
|
assert os.path.exists(p.path)
|
||||||
|
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||||
|
p.temporary = False
|
||||||
|
assert not os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||||
|
|
||||||
|
with open(str(tmpdir / ".gns3_temporary"), "w+") as f:
|
||||||
|
f.write("1")
|
||||||
|
|
||||||
|
p.path = str(tmpdir)
|
||||||
|
assert not os.path.exists(os.path.join(str(tmpdir), ".gns3_temporary"))
|
||||||
|
|
||||||
|
|
||||||
def test_temporary_path():
|
def test_temporary_path():
|
||||||
p = Project(temporary=True)
|
p = Project(temporary=True)
|
||||||
assert os.path.exists(p.path)
|
assert os.path.exists(p.path)
|
||||||
assert os.path.exists(os.path.join(p.path, '.gns3_temporary'))
|
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||||
|
|
||||||
|
|
||||||
def test_remove_temporary_flag():
|
def test_remove_temporary_flag():
|
||||||
p = Project(temporary=True)
|
p = Project(temporary=True)
|
||||||
assert os.path.exists(p.path)
|
assert os.path.exists(p.path)
|
||||||
assert os.path.exists(os.path.join(p.path, '.gns3_temporary'))
|
assert os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||||
p.temporary = False
|
p.temporary = False
|
||||||
assert not os.path.exists(os.path.join(p.path, '.gns3_temporary'))
|
assert not os.path.exists(os.path.join(p.path, ".gns3_temporary"))
|
||||||
|
|
||||||
|
|
||||||
def test_changing_location_not_allowed(tmpdir):
|
def test_changing_location_not_allowed(tmpdir):
|
||||||
|
Loading…
Reference in New Issue
Block a user