Using Go, I was writing a small utility that in part needs to notice if the filename of an open file changes. The below code 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)
}
}
This just starts an endless loop, running file.Stat()
to obtain file details every 5 seconds and then printing out the name. However, despite changing the filename as this is running, the output of the above does not change.
replacing details.Name()
with details.Size()
does however notice changes to the filesize.
Is this simply a bug in my version of Go, or am I just doing things wrong? I cannot find mention of such an issue anywhere offhand.
I am running this on a Mac, with Go version 1.1.1 (darwin/amd64).
Thanks in advance for any replies :)