Skip to content

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

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

Open
patheikkinen opened this issue Mar 19, 2025 · 0 comments

Comments

@patheikkinen
Copy link

patheikkinen commented Mar 19, 2025

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.

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