-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For golang#67002 Change-Id: I546537618cbe32217fa72264d49db2b1a1d3b6db Reviewed-on: https://go-review.googlesource.com/c/go/+/648295 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Damien Neil <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
- Loading branch information
Showing
21 changed files
with
224 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pkg os, method (*Root) Chmod(string, fs.FileMode) error #67002 | ||
pkg os, method (*Root) Chown(string, int, int) error #67002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
The [os.Root] type supports the following additional methods: | ||
|
||
* [os.Root.Chmod] | ||
* [os.Root.Chown] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2025 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build unix || (js && wasm) || wasip1 | ||
|
||
package os_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"runtime" | ||
"syscall" | ||
"testing" | ||
) | ||
|
||
func TestRootChown(t *testing.T) { | ||
if runtime.GOOS == "wasip1" { | ||
t.Skip("Chown not supported on " + runtime.GOOS) | ||
} | ||
|
||
// Look up the current default uid/gid. | ||
f := newFile(t) | ||
dir, err := f.Stat() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
sys := dir.Sys().(*syscall.Stat_t) | ||
|
||
groups, err := os.Getgroups() | ||
if err != nil { | ||
t.Fatalf("getgroups: %v", err) | ||
} | ||
groups = append(groups, os.Getgid()) | ||
for _, test := range rootTestCases { | ||
test.run(t, func(t *testing.T, target string, root *os.Root) { | ||
if target != "" { | ||
if err := os.WriteFile(target, nil, 0o666); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
for _, gid := range groups { | ||
err := root.Chown(test.open, -1, gid) | ||
if errEndsTest(t, err, test.wantError, "root.Chown(%q, -1, %v)", test.open, gid) { | ||
return | ||
} | ||
checkUidGid(t, target, int(sys.Uid), gid) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestRootConsistencyChown(t *testing.T) { | ||
if runtime.GOOS == "wasip1" { | ||
t.Skip("Chown not supported on " + runtime.GOOS) | ||
} | ||
groups, err := os.Getgroups() | ||
if err != nil { | ||
t.Fatalf("getgroups: %v", err) | ||
} | ||
var gid int | ||
if len(groups) == 0 { | ||
gid = os.Getgid() | ||
} else { | ||
gid = groups[0] | ||
} | ||
for _, test := range rootConsistencyTestCases { | ||
test.run(t, func(t *testing.T, path string, r *os.Root) (string, error) { | ||
chown := os.Chown | ||
lstat := os.Lstat | ||
if r != nil { | ||
chown = r.Chown | ||
lstat = r.Lstat | ||
} | ||
err := chown(path, -1, gid) | ||
if err != nil { | ||
return "", err | ||
} | ||
fi, err := lstat(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
sys := fi.Sys().(*syscall.Stat_t) | ||
return fmt.Sprintf("%v %v", sys.Uid, sys.Gid), nil | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters