theskumar / theskumar/python-dotenv

rewrite always finishes with an error when the file is on a Windows host

未关闭
#554 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
8.9k
派生
581
PR 合并指标
30 天内没有已合并 PR

描述

Trying to run iotedgedev in a docker container inside a WSL2 vm always yields the same error:

ERROR: Could not update the environment variable IOTHUB_CONNECTION_STRING in file /home/iotedge/.env

Funny thing is, the variable IS written to the file. What isn't written is the next variable, so clearly an error occurs AFTER having already written the value to the file.

Iotedgedev uses dotenv to update the .env file:

    def save_envvar(self, key, value):
        try:
            dotenv_file = self.get_dotenv_file()
            dotenv_path = os.path.join(os.getcwd(), dotenv_file)
            set_key(dotenv_path, key, value)
        except Exception:
            raise IOError(f("Could not update the environment variable {key} in file {dotenv_path}"))

Now, set_key seems to be using rewrite to update the file, and rewrite does this:

    if error is None:
        shutil.move(dest.name, path)
    else:
        os.unlink(dest.name)
        raise error from None

Instead of plain move it should first do an os.remove and only then move. That should make it work with files on a Windows host.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

Start at save_envvar and trace set_key into the rewrite path shown in the report. Reproduce the .env update with a file on a Windows host or WSL2-mounted path, then verify that the update finishes without an error and that subsequent variables are written.

由索引模型根据 Issue 内容生成。

评估

技术栈
docker, python
领域
devops, operating-systems
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。