The issue noticed in fcaca5f#r31889375 reveals a much larger problem.
Two things are important to make group inheritance work correctly:
- The group of any new file, directory, ... should be set correctly
- For directories, the SGID bit should be preserved
The first point never worked due to the explicit Fchown* we execute when PreserveOwner is enabled. The second point sometimes worked, but this was more pure luck than intentional. For directories created without write/execute permission it never worked due to the explicit Fchmod we executed in that case.
Even with PreserveOwner disabled, group inheritance did not always work (e.g., in the case where we execute an explicit Fchmod on a newly created directory).