github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/sysfs/unlink_windows.go (about)

     1  package sysfs
     2  
     3  import (
     4  	"os"
     5  	"syscall"
     6  
     7  	"github.com/tetratelabs/wazero/experimental/sys"
     8  )
     9  
    10  func unlink(name string) sys.Errno {
    11  	err := syscall.Unlink(name)
    12  	if err == nil {
    13  		return 0
    14  	}
    15  	errno := sys.UnwrapOSError(err)
    16  	if errno == sys.EBADF {
    17  		lstat, errLstat := os.Lstat(name)
    18  		if errLstat == nil && lstat.Mode()&os.ModeSymlink != 0 {
    19  			errno = sys.UnwrapOSError(os.Remove(name))
    20  		} else {
    21  			errno = sys.EISDIR
    22  		}
    23  	}
    24  	return errno
    25  }