Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down