From 6d418096b2dfe2a2e47b7aa83b46748fb301e6cb Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Fri, 28 Mar 2025 16:14:43 -0700 Subject: os: avoid symlink races in RemoveAll on Windows Make the openat-using version of RemoveAll use the appropriate Windows equivalent, via new portable (but internal) functions added for os.Root. We could reimplement everything in terms of os.Root, but this is a bit simpler and keeps the existing code structure. Fixes #52745 Change-Id: I0eba0286398b351f2ee9abaa60e1675173988787 Reviewed-on: https://go-review.googlesource.com/c/go/+/661575 Reviewed-by: Alan Donovan Auto-Submit: Damien Neil LUCI-TryBot-Result: Go LUCI --- src/internal/syscall/unix/constants.go | 2 +- src/internal/syscall/unix/nofollow_posix.go | 2 +- src/internal/syscall/windows/at_windows.go | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/internal') diff --git a/src/internal/syscall/unix/constants.go b/src/internal/syscall/unix/constants.go index 28092c2ddf..6a78dda795 100644 --- a/src/internal/syscall/unix/constants.go +++ b/src/internal/syscall/unix/constants.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build unix +//go:build unix || wasip1 package unix diff --git a/src/internal/syscall/unix/nofollow_posix.go b/src/internal/syscall/unix/nofollow_posix.go index de2ea14fc8..3a5e0af05d 100644 --- a/src/internal/syscall/unix/nofollow_posix.go +++ b/src/internal/syscall/unix/nofollow_posix.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build unix && !dragonfly && !freebsd && !netbsd +//go:build (unix && !dragonfly && !freebsd && !netbsd) || wasip1 package unix diff --git a/src/internal/syscall/windows/at_windows.go b/src/internal/syscall/windows/at_windows.go index f04de276b9..919dda1f50 100644 --- a/src/internal/syscall/windows/at_windows.go +++ b/src/internal/syscall/windows/at_windows.go @@ -188,7 +188,7 @@ func Mkdirat(dirfd syscall.Handle, name string, mode uint32) error { return nil } -func Deleteat(dirfd syscall.Handle, name string) error { +func Deleteat(dirfd syscall.Handle, name string, options uint32) error { objAttrs := &OBJECT_ATTRIBUTES{} if err := objAttrs.init(dirfd, name); err != nil { return err @@ -200,7 +200,7 @@ func Deleteat(dirfd syscall.Handle, name string) error { objAttrs, &IO_STATUS_BLOCK{}, FILE_SHARE_DELETE|FILE_SHARE_READ|FILE_SHARE_WRITE, - FILE_OPEN_REPARSE_POINT|FILE_OPEN_FOR_BACKUP_INTENT|FILE_SYNCHRONOUS_IO_NONALERT, + FILE_OPEN_REPARSE_POINT|FILE_OPEN_FOR_BACKUP_INTENT|FILE_SYNCHRONOUS_IO_NONALERT|options, ) if err != nil { return ntCreateFileError(err, 0) -- cgit v1.3-5-g45d5