diff --git a/tail.go b/tail.go index 2d252d60..f0d804b9 100644 --- a/tail.go +++ b/tail.go @@ -158,6 +158,11 @@ func (tail *Tail) Tell() (offset int64, err error) { return } +// Return the file's stats +func (tail *Tail) FileStat() (os.FileInfo, error) { + return tail.file.Stat() +} + // Stop stops the tailing activity. func (tail *Tail) Stop() error { tail.Kill(nil) diff --git a/tail_test.go b/tail_test.go index 8dcc02c2..8c6134c3 100644 --- a/tail_test.go +++ b/tail_test.go @@ -292,6 +292,27 @@ func TestTell(t *testing.T) { tail.Cleanup() } +func TestFileStat(t *testing.T) { + tailTest := NewTailTest("tell-position", t) + tailTest.CreateFile("test.txt", "hello\nworld\nagain\nmore\n") + config := Config{ + Follow: false, + MustExist: true, + Location: &SeekInfo{0, os.SEEK_SET}} + tail := tailTest.StartTail("test.txt", config) + tail.reopen() + stat, err := tail.FileStat() + if err != nil { + tailTest.Errorf("FileStat return error: %s", err.Error()) + } + if size := stat.Size(); size != 23 { + tailTest.Fatalf("mismatch; expected 23, but got %d", size) + } + tailTest.RemoveFile("test.txt") + tail.Done() + tail.Cleanup() +} + func TestBlockUntilExists(t *testing.T) { tailTest := NewTailTest("block-until-file-exists", t) config := Config{