Skip to content

Commit 4058007

Browse files
authored
chore: Ensure newly created files have a reasonable owner (googleapis#2465)
1 parent 82d8580 commit 4058007

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

script/synth.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ def execute cmd
1515
# so any previously created files don't pollute this and subsequent synth runs.
1616
execute "git clean -df"
1717

18-
Dir.chdir "google-apis-generator"
18+
# This script is generally run as a superuser in a container. As a result,
19+
# newly generated files will have a superuser owner, and cannot easily be
20+
# removed by the caller. Thus, we must ensure any files generated during this
21+
# run are given a reasonable owner before the script exits.
22+
at_exit do
23+
user_group = ENV["USER_GROUP"]
24+
execute "chown -R #{user_group} #{DIR}/generated" if user_group
25+
end
1926

27+
Dir.chdir "google-apis-generator"
2028
execute "bundle install"
2129

2230
if ARGV.empty?

synth.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
f"-v{os.getcwd()}:/workspace",
3232
"-v/var/run/docker.sock:/var/run/docker.sock",
3333
"-w", "/workspace",
34+
"-e", f"USER_GROUP={os.getuid()}:{os.getgid()}",
3435
"--entrypoint", "script/synth.rb",
3536
"gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/autosynth"]
3637
if extra_args():

0 commit comments

Comments
 (0)