buildkite / elastic-ci-stack-for-aws

An auto-scaling cluster of build agents running in your own AWS VPC
https://buildkite.com/docs/quickstart/elastic-ci-stack-aws
MIT License
414 stars 265 forks source link

Avoid chowning files with expected ownership #1333

Closed rianmcguire closed 1 week ago

rianmcguire commented 1 week ago

Calling fchownat on a file updates the file's ctime (metadata update time), even if uid and gid don't change.

Git uses ctime (along with other metadata) to determine if checked out files have been modified. If the ctime has changed, it rewrites the contents of the file during checkout.

This makes git checkouts in already cloned repos slower than they need to be:

# Checking out a commit
[buildkite-agent@ip-10-0-1-159 linux]$ time git checkout -f 626737a5791b
HEAD is now at 626737a5791b Merge tag 'pinctrl-v6.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl

real    0m0.255s
user    0m0.130s
sys     0m0.235s

# Run fix permissions
[buildkite-agent@ip-10-0-1-159 linux]$ /usr/bin/fix-buildkite-agent-builds-permissions buildkite-rian-i-0868df7f3b3f2c10d-1 rians-test-org linux

# Checkout the same commit
[buildkite-agent@ip-10-0-1-159 linux]$ time git checkout -f 626737a5791b
Updating files: 100% (84961/84961), done.
HEAD is now at 626737a5791b Merge tag 'pinctrl-v6.10-2' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-pinctrl

real    0m14.180s
user    0m6.461s
sys     0m4.178s

This PR teaches fixperms to check the current uid/gid and skip calling chown if nothing will change.