Using Go, I wrote a small utility that partially needs to notice if the file of the open file changes. The code below illustrates the approach I tried:
package main import "os" import "fmt" import "time" func main() { path := "data.txt" file, _ := os.Open(path) for { details, _ := file.Stat() fmt.Println(details.Name()) time.Sleep(5 * time.Second) } }
It just starts an endless loop by running file.Stat() to get file information every 5 seconds and then print the name. However, despite the change in the file name when it is launched, the output of the above does not change.
replacing details.Name() with details.Size() , however notice changes in file size.
Is this just a bug in my version of Go, or am I just doing something wrong? I cannot find mention of such a problem anywhere.
I run this on a Mac with Go version 1.1.1 (darwin / amd64).
Thanks for any answers :)
source share