1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-26 00:38:10 +00:00

Do not export/import symlinks for projects. Fixes #2699

This commit is contained in:
grossmj 2019-02-19 12:43:44 +07:00
parent 589c9754e8
commit ae3515434c
2 changed files with 12 additions and 3 deletions

View File

@ -64,7 +64,7 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
yield from _patch_project_file(project, os.path.join(project._path, file), zstream, include_images, keep_compute_id, allow_all_nodes, temporary_dir) yield from _patch_project_file(project, os.path.join(project._path, file), zstream, include_images, keep_compute_id, allow_all_nodes, temporary_dir)
# Export the local files # Export the local files
for root, dirs, files in os.walk(project._path, topdown=True): for root, dirs, files in os.walk(project._path, topdown=True, followlinks=False):
files = [f for f in files if _is_exportable(os.path.join(root, f))] files = [f for f in files if _is_exportable(os.path.join(root, f))]
for file in files: for file in files:
path = os.path.join(root, file) path = os.path.join(root, file)
@ -125,6 +125,7 @@ def _patch_mtime(path):
new_mtime = file_date.replace(year=1980).timestamp() new_mtime = file_date.replace(year=1980).timestamp()
os.utime(path, (st.st_atime, new_mtime)) os.utime(path, (st.st_atime, new_mtime))
def _is_exportable(path): def _is_exportable(path):
""" """
:returns: True if file should not be included in the final archive :returns: True if file should not be included in the final archive
@ -134,6 +135,10 @@ def _is_exportable(path):
if path.endswith("snapshots"): if path.endswith("snapshots"):
return False return False
# do not export symlinks
if os.path.islink(path):
return False
# do not export directories of snapshots # do not export directories of snapshots
if "{sep}snapshots{sep}".format(sep=os.path.sep) in path: if "{sep}snapshots{sep}".format(sep=os.path.sep) in path:
return False return False

View File

@ -184,9 +184,11 @@ def _move_files_to_compute(compute, project_id, directory, files_path):
location = os.path.join(directory, files_path) location = os.path.join(directory, files_path)
if os.path.exists(location): if os.path.exists(location):
for (dirpath, dirnames, filenames) in os.walk(location): for (dirpath, dirnames, filenames) in os.walk(location, followlinks=False):
for filename in filenames: for filename in filenames:
path = os.path.join(dirpath, filename) path = os.path.join(dirpath, filename)
if os.path.islink(path):
continue
dst = os.path.relpath(path, directory) dst = os.path.relpath(path, directory)
yield from _upload_file(compute, project_id, path, dst) yield from _upload_file(compute, project_id, path, dst)
yield from wait_run_in_executor(shutil.rmtree, os.path.join(directory, files_path)) yield from wait_run_in_executor(shutil.rmtree, os.path.join(directory, files_path))
@ -213,9 +215,11 @@ def _import_images(controller, path):
image_dir = controller.images_path() image_dir = controller.images_path()
root = os.path.join(path, "images") root = os.path.join(path, "images")
for (dirpath, dirnames, filenames) in os.walk(root): for (dirpath, dirnames, filenames) in os.walk(root, followlinks=False):
for filename in filenames: for filename in filenames:
path = os.path.join(dirpath, filename) path = os.path.join(dirpath, filename)
if os.path.islink(path):
continue
dst = os.path.join(image_dir, os.path.relpath(path, root)) dst = os.path.join(image_dir, os.path.relpath(path, root))
os.makedirs(os.path.dirname(dst), exist_ok=True) os.makedirs(os.path.dirname(dst), exist_ok=True)
shutil.move(path, dst) shutil.move(path, dst)