Skip to content

Conversation

@kolyshkin
Copy link
Contributor

@kolyshkin kolyshkin commented Feb 17, 2022

What does this pull request do?

  1. Simplifies lint CI job by removing go vet and gofmt (those are called by golangci-lint anyway).

  2. Fixes all warnings found by the default set of golangci-lint checkers. In some cases those are real bugs, so please review carefully.

  3. Stop ignoring golangci-lint warnings.

Where should the reviewer start?

Please review commit by commit, noting the commit messages.

⚠️ Currently the linters only check the code for the current platform (that is, Linux). There are multiple issues with *bsd and windows (those can be seen from CLI using e.g. GOOS=darwin golangci-lint run) that I am afraid to tackle.

How should this be manually tested?

No manual tests needed; this is why we have CI! 😉 👌🏻

Those are run by golangci-lint, so we don't have to.

Signed-off-by: Kir Kolyshkin <[email protected]>
Fix these:

	inotify_test.go:134:7: S1005: unnecessary assignment to the blank identifier (gosimple)
		case _ = <-w.Events:
		     ^
	inotify_test.go:351:2: S1005: unnecessary assignment to the blank identifier (gosimple)
		_ = <-w.Events                      // consume Remove event
		^

Signed-off-by: Kir Kolyshkin <[email protected]>
The staticcheck linter suggests:

	inotify_test.go:146:2: SA5001: should check returned error before deferring w.Close() (staticcheck)
		defer w.Close()
		^

Instead, remove the defer entirely because we have one already earlier
in the code.

Signed-off-by: Kir Kolyshkin <[email protected]>
The staticcheck linter warns:

	inotify_poller.go:122:5: SA9003: empty branch (staticcheck)
					if event.Events&unix.EPOLLHUP != 0 {
					^

Commit 8165837 removed the code that handles this case,
so it is no longer needed. The comment would be nice to have, but it
is sort of obvious.

Signed-off-by: Kir Kolyshkin <[email protected]>
Check for and return an error in case w.poller.wake() failed, to fix
this warning:

	inotify.go:83:15: Error return value of `w.poller.wake` is not checked (errcheck)
		w.poller.wake()
			     ^

Signed-off-by: Kir Kolyshkin <[email protected]>
1. Add t.Helper() call to newWatcher() and addWatch() helper functions
   for tests to show proper file/line information on errors.

2. Fix addWatch argument name and docstring since it is not always a
   directory.

3. Use newWatcher and addWatch where possible, fixing a few cases of
   missing error checks.

4. Fix a case where os.Create() result is not checked, and the resulting
   file is not closed.

5. Some related refactoring.

Signed-off-by: Kir Kolyshkin <[email protected]>
1. Fix two cases where the test tries to write to a file which was
   opened read-only.

2. Add and use helper functions ok() and writeData() to aid in tests
   error checking.

Signed-off-by: Kir Kolyshkin <[email protected]>
At the moment there should be none.

Signed-off-by: Kir Kolyshkin <[email protected]>
@kolyshkin kolyshkin marked this pull request as ready for review February 17, 2022 04:14
@kolyshkin kolyshkin mentioned this pull request Feb 17, 2022
@kolyshkin kolyshkin requested a review from Code0x58 February 18, 2022 00:31
w.poller.wake()
if err := w.poller.wake(); err != nil {
return fmt.Errorf("poller.wake failed: %w", err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure if this is really the correct behaviour; I think that this failing isn't really a big deal in the Close() here?

if event.Events&unix.EPOLLHUP != 0 {
// Write pipe descriptor was closed, by us. This means we're closing down the
// watcher, and we should wake up.
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says it "should wake up", but it doesn't do anything. I'm not sure if this can just be removed, or if there's an omission here and we should put something in this branch.

@arp242
Copy link
Member

arp242 commented Jul 30, 2022

Should be fixed in the main branch now.

@arp242 arp242 closed this Jul 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants