Skip to content

Commit

Permalink
Do not export/import symlinks for projects. Fixes #2699
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Feb 19, 2019
1 parent 589c975 commit ae35154
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion gns3server/controller/export_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions gns3server/controller/import_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)

0 comments on commit ae35154

Please sign in to comment.