Skip to content

Commit 6321460

Browse files
committed
Use mktmpdir instead of hard-coded /tmp
1 parent 206c9df commit 6321460

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

example_app/github_repo_helper.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ def shell_create_and_push_commit(repo_credentials, application_name)
5454
private_key = repo_credentials["private_key"]
5555
repo_name = repo_credentials["name"]
5656
repo_ssh_url = repo_credentials["ssh_url"]
57-
keys_dir = "/tmp/github_keys"
57+
temp_dir = Dir.mktmpdir
58+
keys_dir = "#{temp_dir}/github_keys"
5859
key_file_name = "#{keys_dir}/#{repo_name}.key"
59-
git_ssh_script = "/tmp/#{repo_name}_ssh_script.sh"
60-
known_hosts_file = "/tmp/github_known_hosts"
60+
git_ssh_script = "#{temp_dir}/#{repo_name}_ssh_script.sh"
61+
known_hosts_file = "#{temp_dir}/github_known_hosts"
6162

6263
# Create directory for storing key file, and set permissions
6364
`if [ ! -d #{keys_dir} ]; then mkdir #{keys_dir}; fi`
@@ -87,14 +88,13 @@ def shell_create_and_push_commit(repo_credentials, application_name)
8788
end
8889

8990
commands = [
90-
"cd /tmp; GIT_SSH=#{git_ssh_script} git clone #{repo_ssh_url} 2>&1",
91-
"cd /tmp/#{repo_name} && git config user.name '#{application_name}' 2>&1",
92-
"cd /tmp/#{repo_name} && git commit --allow-empty -m 'auto generated empty commit' 2>&1",
93-
"cd /tmp/#{repo_name} && git log --pretty=format:\"%h%x09%ad%x09%s\" 2>&1",
94-
"cd /tmp/#{repo_name}; GIT_SSH=#{git_ssh_script} git push origin master 2>&1"
91+
"cd #{temp_dir}; GIT_SSH=#{git_ssh_script} git clone #{repo_ssh_url} 2>&1",
92+
"cd #{temp_dir}/#{repo_name} && git config user.name '#{application_name}' 2>&1",
93+
"cd #{temp_dir}/#{repo_name} && git commit --allow-empty -m 'auto generated empty commit' 2>&1",
94+
"cd #{temp_dir}/#{repo_name} && git log --pretty=format:\"%h%x09%ad%x09%s\" 2>&1",
95+
"cd #{temp_dir}/#{repo_name}; GIT_SSH=#{git_ssh_script} git push origin master 2>&1"
9596
]
9697

97-
9898
return_code = 0
9999
output = ""
100100

@@ -109,7 +109,7 @@ def shell_create_and_push_commit(repo_credentials, application_name)
109109
cleanup_commands = [
110110
"rm #{key_file_name}",
111111
"rm #{git_ssh_script}",
112-
"rm -rf /tmp/#{repo_name}"
112+
"rm -rf #{temp_dir}/#{repo_name}"
113113
]
114114

115115
cleanup_commands.each do |command|
@@ -131,4 +131,4 @@ def credentials_are_present?(credentials)
131131
blank?(credentials["ssh_url"]) ||
132132
blank?(credentials["private_key"]))
133133
end
134-
end
134+
end

0 commit comments

Comments
 (0)