Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added fix and test to tail issue #8

Merged
merged 1 commit into from
Jan 20, 2022
Merged
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
30 changes: 30 additions & 0 deletions tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,28 @@ func reSeek(t *testing.T, poll bool) {
tailTest.Cleanup(tail, false)
}

func TestPermissionChange(t *testing.T) {
tailTest := NewTailTest("change-permission", t)
tailTest.CreateFile("test.txt", "a really long string goes here\nhello\nworld\n")

tail := tailTest.StartTail(
"test.txt",
Config{Follow: true, ReOpen: true, Poll: false})

<-time.After(100 * time.Millisecond)

content := []string{"a really long string goes here", "hello", "world"}
go tailTest.VerifyTailOutput(tail, content, false)

tailTest.ChangeFilePermssions("test.txt", 0200)

<-time.After(100 * time.Millisecond)

tailTest.ChangeFilePermssions("test.txt", 0600)

tailTest.Cleanup(tail, true)
}

// Test library

type TailTest struct {
Expand Down Expand Up @@ -484,6 +506,14 @@ func (t TailTest) RenameFile(oldname string, newname string) {
}
}

func (t TailTest) ChangeFilePermssions(name string, mode os.FileMode) {
fPath := t.path + "/" + name
err := os.Chmod(fPath, mode)
if err != nil {
t.Fatal(err)
}
}

func (t TailTest) AppendFile(name string, contents string) {
f, err := os.OpenFile(t.path+"/"+name, os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions watch/inotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ func (fw *InotifyFileWatcher) ChangeEvents(t *tomb.Tomb, pos int64) (*FileChange
changes.NotifyDeleted()
return
}

if os.IsPermission(err) {
util.LOGGER.Printf("Permission error on file %v: %v\n", fw.Filename, err)
continue
}

// XXX: report this error back to the user
util.Fatal("Failed to stat file %v: %v", fw.Filename, err)
}
Expand Down