From 49d24d469eb4ecbbf5a77d905ca2bd1da0e18bbd Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 12 Nov 2024 17:16:10 +0100 Subject: os: add Root.Remove For #67002 Change-Id: Ibbf44c0bf62f53695a7399ba0dae5b84d5efd374 Reviewed-on: https://go-review.googlesource.com/c/go/+/627076 Reviewed-by: Quim Muntal Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- src/os/root_unix.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/os/root_unix.go') diff --git a/src/os/root_unix.go b/src/os/root_unix.go index 496a11903b..6f8f9c8e3e 100644 --- a/src/os/root_unix.go +++ b/src/os/root_unix.go @@ -119,6 +119,28 @@ func mkdirat(fd int, name string, perm FileMode) error { }) } +func removeat(fd int, name string) error { + // The system call interface forces us to know whether + // we are removing a file or directory. Try both. + e := ignoringEINTR(func() error { + return unix.Unlinkat(fd, name, 0) + }) + if e == nil { + return nil + } + e1 := ignoringEINTR(func() error { + return unix.Unlinkat(fd, name, unix.AT_REMOVEDIR) + }) + if e1 == nil { + return nil + } + // Both failed. See comment in Remove for how we decide which error to return. + if e1 != syscall.ENOTDIR { + return e1 + } + return e +} + // checkSymlink resolves the symlink name in parent, // and returns errSymlink with the link contents. // -- cgit v1.3