You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you have a directory whose template resolve to an empty string, it will do one of two bad things:
If you are running normally, it will give an error about the directory already existing
If you run with overwrite-if-exists, bad stuff happens culminating in a permission denied error
This is happening, because the render_and_create_dir method joins the generate path with its parent to produce a new one. If the generated path is empty, the resulting path is the same as its parent. This behavior is clearly undesirable.
I think an empty directory name (and filename) for that matter should be omitted entirely, perhaps with a warning
What I've run:
$ cat dump.txt
$ tree
.
├── cookiecutter.json
└── {{cookiecutter.project_name}}
├── README.md
└── {{cookiecutter.foolish}}
└── BOOM.md
2 directories, 3 files
$ cat cookiecutter.json
{
"project_name": "boom-test",
"foolish": ""
}
$ cookiecutter --output-dir=.. .
project_name [boom-test]:
foolish []:
Error: "/home/dusktreader/boom-test" directory already exists
$ cookiecutter --output-dir=.. . -f
project_name [boom-test]:
foolish []:
Traceback (most recent call last):
File "/home/dusktreader/.pyenv/versions/3.8.7/bin/cookiecutter", line 8, in <module>
sys.exit(main())
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/cookiecutter/cli.py", line 140, in main
cookiecutter(
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/cookiecutter/main.py", line 101, in cookiecutter
result = generate_files(
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/cookiecutter/generate.py", line 352, in generate_files
generate_file(
File "/home/dusktreader/.pyenv/versions/3.8.7/lib/python3.8/site-packages/cookiecutter/generate.py", line 179, in generate_file
with io.open(outfile, 'w', encoding='utf-8') as fh:
PermissionError: [Errno 13] Permission denied: '/BOOM.md'
The text was updated successfully, but these errors were encountered:
Description:
If you have a directory whose template resolve to an empty string, it will do one of two bad things:
This is happening, because the
render_and_create_dir
method joins the generate path with its parent to produce a new one. If the generated path is empty, the resulting path is the same as its parent. This behavior is clearly undesirable.I think an empty directory name (and filename) for that matter should be omitted entirely, perhaps with a warning
What I've run:
The text was updated successfully, but these errors were encountered: