Skip to content

Skip Setgid test when we cannot set this bit - #415

Merged
folbricht merged 1 commit into
folbricht:masterfrom
matshch:skip-setgid
Sep 2, 2026
Merged

folbricht merged 1 commit into
folbricht:masterfrom
matshch:skip-setgid

Conversation

@matshch

@matshch matshch commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Some environments are too restricted to set setgid, so check that we can do that before expecting the rest of the code to do that.

Some environments are too restricted to set setgid, so check that we can do
that before expecting the rest of the code to do that.
@folbricht

Copy link
Copy Markdown
Owner

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

The probe mirrors the sequence the code under test actually uses — prepareDirWrite creates the directory with n.Mode.Perm() (setgid stripped) and chmods the bit back in — so os.Mkdir followed by os.Chmod(…|os.ModeSetgid) is a faithful capability check, and the stat re-read covers the case where chmod reports success but the bit is not preserved.

desync/localfs_other.go

Lines 106 to 114 in f1a54c4

}
// Newly created directories are chmod'ed as well, both to undo a umask
// that stripped the bits we need and to set the setuid/setgid/sticky bits
// that mkdir doesn't apply. A setgid directory has to carry that bit while
// its contents are created for them to inherit the group.
if created || existing&0300 != 0300 {
_ = r.Chmod(n.Name, n.Mode|0700)
}
}

The skip is additive: the assertions are untouched, so coverage is unchanged wherever setgid works. It also matches the existing convention for environment-dependent skips in this package.

// the contents of a directory are written, so they inherit its group.
func TestLocalFSDirSetgidWhilePopulated(t *testing.T) {
// Some build sandboxes prevent us from setting setgid bit
probe := filepath.Join(t.TempDir(), "setgid")
require.NoError(t, os.Mkdir(probe, 0755))
if err := os.Chmod(probe, 0775|os.ModeSetgid); err != nil {
t.Skipf("setgid on a directory is not permitted here: %v", err)
}
// Some environments do not preserve setgid, e.g. macOS with TMPDIR=/tmp
info, err := os.Stat(probe)
require.NoError(t, err)
if info.Mode()&os.ModeSetgid == 0 {
t.Skip("setgid on a directory is not preserved here")
}

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@folbricht
folbricht merged commit cc9a78c into folbricht:master Sep 2, 2026
9 checks passed
@matshch
matshch deleted the skip-setgid branch September 2, 2026 20:09
@matshch matshch mentioned this pull request Sep 3, 2026
7 of 13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址