Skip to content

GIT_SSH script file handle not yet closed when clone command issued. #3381

@croth1

Description

@croth1

Hi, this code fragment somehow can have unexpected behaviour on (some?) linux machines. For me subprocess.check_call fails, because on the OS side, the file handle to the temporary file has not been closed yet (despite the explicit .close() statement) - debugging the check_call leads to a Text file busy error message).

with tempfile.NamedTemporaryFile() as sshnoprompt:
write_pipe = open(sshnoprompt.name, "w")
write_pipe.write("ssh -oBatchMode=yes $@")
write_pipe.close()
os.chmod(sshnoprompt.name, 0o511)
my_env["GIT_SSH"] = sshnoprompt.name
subprocess.check_call(["git", "clone", repo_url, dest_dir], env=my_env)

Interestingly, the code works fine on my mac, so the behaviour seems somewhat OS dependent.

Instead, changing the NamedTemporaryFile to a TemporaryDirectory and creating the helper script within the context manager of the TemporaryDirectory should work, I think.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions