feat: Implement Lchown function for changing file ownership (#5161)

* feat: Implement Lchown function for changing file ownership

- Added Lchown function to change the numeric uid and gid of a file or symbolic link.
- Included error handling to return *PathError for failed operations.
- Added unit tests for Lchown to verify behavior on different error scenarios.

* fix: fix chmod tests
This commit is contained in:
Itxaka
2026-01-10 09:31:22 +01:00
committed by GitHub
parent 743bf45e00
commit ca36fba7e4
3 changed files with 63 additions and 0 deletions
+13
View File
@@ -166,6 +166,19 @@ func Chown(name string, uid, gid int) error {
return nil
}
// Lchown changes the numeric uid and gid of the named file.
// If the file is a symbolic link, it changes the uid and gid of the link itself.
// If there is an error, it will be of type [*PathError].
//
// If there is an error, it will be of type *PathError.
func Lchown(name string, uid, gid int) error {
e := ignoringEINTR(func() error { return syscall.Lchown(name, uid, gid) })
if e != nil {
return &PathError{Op: "lchown", Path: name, Err: e}
}
return nil
}
// ignoringEINTR makes a function call and repeats it if it returns an
// EINTR error. This appears to be required even though we install all
// signal handlers with SA_RESTART: see #22838, #38033, #38836, #40846.