1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 17:28:08 +00:00

Fix bug with other directory of Qemu images

Fix https://github.com/GNS3/gns3-gui/issues/1790
This commit is contained in:
Julien Duponchelle 2017-01-18 12:39:10 +01:00
parent 3c0bdd12b5
commit e5dba5e66a
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 21 additions and 4 deletions

View File

@ -418,7 +418,7 @@ class BaseManager:
# Not found we try the default directory
s = os.path.split(orig_path)
path = force_unix_path(os.path.join(self.get_images_directory(), *s))
path = force_unix_path(os.path.join(img_directory, *s))
if os.path.exists(path):
return path
raise ImageMissingError(orig_path)
@ -436,7 +436,7 @@ class BaseManager:
if os.path.exists(path):
return path
raise ImageMissingError(orig_path)
raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, self.get_images_directory()))
raise NodeError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory))
def _recursive_search_file_in_directory(self, directory, searched_file):
"""
@ -468,9 +468,15 @@ class BaseManager:
if not path:
return ""
path = force_unix_path(self.get_abs_image_path(path))
img_directory = self.get_images_directory()
for directory in images_directories(self._NODE_TYPE):
if os.path.commonprefix([directory, path]) == directory:
return os.path.relpath(path, directory)
relpath = os.path.relpath(path, directory)
# We don't allow to recurse search from the top image directory just for image type directory (compatibility with old releases)
if os.sep not in relpath or directory == img_directory:
return relpath
return path
@asyncio.coroutine

View File

@ -186,6 +186,7 @@ def test_get_abs_image_recursive_ova(qemu, tmpdir, config):
def test_get_relative_image_path(qemu, tmpdir, config):
os.makedirs(str(tmpdir / "images1" / "QEMU"))
os.makedirs(str(tmpdir / "images1" / "VBOX"))
path1 = force_unix_path(str(tmpdir / "images1" / "test1.bin"))
open(path1, 'w+').close()
@ -196,9 +197,17 @@ def test_get_relative_image_path(qemu, tmpdir, config):
path3 = force_unix_path(str(tmpdir / "images2" / "test3.bin"))
open(path3, 'w+').close()
path4 = force_unix_path(str(tmpdir / "test4.bin"))
open(path4, 'w+').close()
# The user use an image of another emulator we return the full path
path5 = force_unix_path(str(tmpdir / "images1" / "VBOX" / "test5.bin"))
open(path5, 'w+').close()
config.set_section_config("Server", {
"images_path": str(tmpdir / "images1"),
"additional_images_path": str(tmpdir / "images2")
"additional_images_path": str(tmpdir / "images2"),
"local": True
})
assert qemu.get_relative_image_path(path1) == "test1.bin"
assert qemu.get_relative_image_path("test1.bin") == "test1.bin"
@ -206,6 +215,8 @@ def test_get_relative_image_path(qemu, tmpdir, config):
assert qemu.get_relative_image_path("test2.bin") == "test2.bin"
assert qemu.get_relative_image_path("../test1.bin") == "test1.bin"
assert qemu.get_relative_image_path("test3.bin") == "test3.bin"
assert qemu.get_relative_image_path(path4) == path4
assert qemu.get_relative_image_path(path5) == path5
def test_get_relative_image_path_ova(qemu, tmpdir, config):