mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-23 23:38:21 +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")
|
||||
|
||||
self._path = path
|
||||
self._update_temporary_file()
|
||||
|
||||
@property
|
||||
def vms(self):
|
||||
@ -132,6 +133,13 @@ class Project:
|
||||
return
|
||||
|
||||
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:
|
||||
try:
|
||||
|
@ -53,21 +53,37 @@ def test_path(tmpdir):
|
||||
p = Project(location=str(tmpdir))
|
||||
assert p.path == 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():
|
||||
p = Project(temporary=True)
|
||||
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():
|
||||
p = Project(temporary=True)
|
||||
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
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user