Skip to content

Commit a5174c4

Browse files
committed
fix: Fix writing into non-closed file with git clone command
1 parent a9ac311 commit a5174c4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/sagemaker/git_utils.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,13 @@ def _run_clone_command(repo_url, dest_dir):
279279
subprocess.check_call(["git", "clone", repo_url, dest_dir], env=my_env)
280280
elif repo_url.startswith("git@") or repo_url.startswith("ssh://"):
281281
try:
282-
with tempfile.NamedTemporaryFile() as sshnoprompt:
283-
with open(sshnoprompt.name, "w") as write_pipe:
284-
write_pipe.write("ssh -oBatchMode=yes $@")
285-
os.chmod(sshnoprompt.name, 0o511)
286-
my_env["GIT_SSH"] = sshnoprompt.name
282+
with tempfile.TemporaryDirectory() as tmp_dir:
283+
custom_ssh_executable = Path(tmp_dir) / "ssh_batch"
284+
with open(custom_ssh_executable, "w") as pipe:
285+
print("#!/bin/sh", file=pipe)
286+
print("ssh -oBatchMode=yes $@", file=pipe)
287+
os.chmod(custom_ssh_executable, 0o511)
288+
my_env["GIT_SSH"] = str(custom_ssh_executable)
287289
subprocess.check_call(["git", "clone", repo_url, dest_dir], env=my_env)
288290
except subprocess.CalledProcessError:
289291
del my_env["GIT_SSH"]

0 commit comments

Comments
 (0)