theskumar / theskumar/python-dotenv
dotenv-cli - rewrite() does not resolve symlinks
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.9k
- Forks
- 581
- PR merge metrics
- No merged PRs in 30d
Description
While having a play around w/ dotenv today, I noticed that if my .env file was symlinked elsewhere, using the CLI utility via dotenv set or dotenv unset would not work as I expected it to, so I made this small change to the rewrite function:
diff --git a/src/dotenv/main.py b/src/dotenv/main.py
index 052de05..3606abe 100644
--- a/src/dotenv/main.py
+++ b/src/dotenv/main.py
@@ -132,8 +132,12 @@ def rewrite(
path: StrPath,
encoding: Optional[str],
) -> Iterator[Tuple[IO[str], IO[str]]]:
- pathlib.Path(path).touch()
+ path = pathlib.Path(path)
+ if path.is_symlink():
+ path = path.resolve()
+
+ path.touch()
with tempfile.NamedTemporaryFile(mode="w", encoding=encoding, delete=False) as dest:
error = None
try:
This does what I want, but I'm not sure if there are disadvantages to this. I know symlinks are more widely used on linux, but if I'm not mistaken I think this would work on Windows too, since dotenv works with files and not directories.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/dotenv/main.py at the rewrite() function and review how dotenv set and dotenv unset handle a symlinked .env path. Verify the behavior with a symlinked file on the supported platforms; done means those CLI operations update the target file as expected without breaking regular paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100