github.com/iceber/iouring-go@v0.0.0-20230403020409-002cfd2e2a90/examples/symlink/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/iceber/iouring-go"
     9  )
    10  
    11  func main() {
    12  	if len(os.Args) != 3 {
    13  		fmt.Printf("Usage: %s target link\n", os.Args[0])
    14  		return
    15  	}
    16  	target := os.Args[1]
    17  	link := os.Args[2]
    18  
    19  	iour, err := iouring.New(1)
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  	defer iour.Close()
    24  
    25  	linkDir, err := os.Open(filepath.Dir(link))
    26  	if err != nil {
    27  		fmt.Printf("open directory error: %v\n", err)
    28  		return
    29  	}
    30  	defer linkDir.Close()
    31  
    32  	pr, err := iouring.Symlinkat(target, int(linkDir.Fd()), filepath.Base(link))
    33  	if err != nil {
    34  		fmt.Printf("prep request error: %v\n", err)
    35  		return
    36  	}
    37  	request, err := iour.SubmitRequest(pr, nil)
    38  	<-request.Done()
    39  	if err := request.Err(); err != nil {
    40  		fmt.Printf("submit iouring request error: %v\n", err)
    41  		return
    42  	}
    43  }