diff --git a/gns3server/controller/export_project.py b/gns3server/controller/export_project.py index b8cd5a0c..4e376e50 100644 --- a/gns3server/controller/export_project.py +++ b/gns3server/controller/export_project.py @@ -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) # 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))] for file in files: path = os.path.join(root, file) @@ -125,6 +125,7 @@ def _patch_mtime(path): new_mtime = file_date.replace(year=1980).timestamp() os.utime(path, (st.st_atime, new_mtime)) + def _is_exportable(path): """ :returns: True if file should not be included in the final archive @@ -134,6 +135,10 @@ def _is_exportable(path): if path.endswith("snapshots"): return False + # do not export symlinks + if os.path.islink(path): + return False + # do not export directories of snapshots if "{sep}snapshots{sep}".format(sep=os.path.sep) in path: return False diff --git a/gns3server/controller/import_project.py b/gns3server/controller/import_project.py index a5a89661..83603c17 100644 --- a/gns3server/controller/import_project.py +++ b/gns3server/controller/import_project.py @@ -184,9 +184,11 @@ def _move_files_to_compute(compute, project_id, directory, files_path): location = os.path.join(directory, files_path) 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: path = os.path.join(dirpath, filename) + if os.path.islink(path): + continue dst = os.path.relpath(path, directory) yield from _upload_file(compute, project_id, path, dst) 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() 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: path = os.path.join(dirpath, filename) + if os.path.islink(path): + continue dst = os.path.join(image_dir, os.path.relpath(path, root)) os.makedirs(os.path.dirname(dst), exist_ok=True) shutil.move(path, dst)