1
golang의 syscall 라이브러리에서 inotify 기능을 사용하고 있습니다. InotifyInit
으로 inotify 기능을 설정하고 InotifyAddWatch
으로보고 파일을 추가하고 Read
기능으로 파일 변경을 감지 할 수 있습니다. 내가 가지고있는 문제는 Read
함수가 inotify 이벤트에 대한 정보가 들어있는 바이트 배열로만 읽는 것입니다. 내가 제대로 inotify를 이벤트에 대한바이트 배열을 syscall.InotifyEvent 구조체로 변환합니다.
을 정보에 액세스 할 수 있도록 I 다음은 내가 지금까지 무엇을 인 InotifyEvent
구조로/그 바이트 배열을 캐스팅 변환하고 싶습니다 : 당신의 도움에 대한
package main
import (
"fmt"
"syscall"
)
func main() {
buff := make([]byte, 64)
inotefd, err := syscall.InotifyInit()
if err != nil {
fmt.Println(err)
}
_, err = syscall.InotifyAddWatch(inotefd, "/home/me/foo", syscall.IN_MODIFY)
if err != nil {
fmt.Println(err)
}
for {
n, err := syscall.Read(inotefd, buff)
if err != nil {
fmt.Println(err)
return
}
if n < 0 {
fmt.Println("Read Error")
return
}
fmt.Printf("Buffer: %v\n", buff)
//can't cast []buff into InotifyEvent struct
fmt.Printf("Cookie: %v\n", buff[0:4])
fmt.Printf("Len: %v\n", buff[4:8])
fmt.Printf("Mask: %v\n", buff[8:12])
fmt.Printf("Name: %v\n", buff[12:13])
fmt.Printf("Wd: %v\n", buff[13:17])
}
}
감사합니다!