Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error if symlink is present in project #101

Closed
next-franciscoalgaba opened this issue Mar 16, 2021 · 0 comments
Closed

Update error if symlink is present in project #101

next-franciscoalgaba opened this issue Mar 16, 2021 · 0 comments

Comments

@next-franciscoalgaba
Copy link
Contributor

Description

If in the project template to update there is a symlink, the operation raises an OSError when calling the function _remove_paths in the cruft/_commands/utils/generate.py file.

cruft/_commands/update.py", line 78, in update
    deleted_paths=deleted_paths,
cruft/_commands/utils/generate.py", line 47, in cookiecutter_template
    _remove_paths(output_dir, skip_paths | deleted_paths)
cruft/_commands/utils/generate.py", line 119, in _remove_paths
    rmtree(path)
  File "/usr/lib/python3.6/shutil.py", line 490, in rmtree
    onerror(os.path.islink, path, sys.exc_info())
  File "/usr/lib/python3.6/shutil.py", line 488, in rmtree
    raise OSError("Cannot call rmtree on a symbolic link")
OSError: Cannot call rmtree on a symbolic link

Related Issue

To recreate the bug create a symlink in the new template version to upgrade and perform a cruft update ... over the old template.

How Has This Been Tested?

In order to fix the described behaviour, the following code is proposed in the PR associated with this issue. The changes made are in the cruft/_commands/utils/generate.py file and _remove_paths function:

def _remove_paths(root: Path, paths_to_remove: Union[Set[Path], Set[str]]):
    for path_to_remove in paths_to_remove:
        for path in root.glob(str(path_to_remove)):
            if path.is_file() or path.is_symlink():
                path.unlink()
            elif path.is_dir():
                rmtree(path)

The method unlink() in the path attribute has native support for symlinks but in the function code the case is not contemplated and is treated as a folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant