This file is indexed.

/usr/share/gocode/src/github.com/ncw/swift/timeout_reader.go is in golang-github-ncw-swift-dev 0.0~git20151108.0.eb694f7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package swift

import (
	"io"
	"time"
)

// An io.ReadCloser which obeys an idle timeout
type timeoutReader struct {
	reader  io.ReadCloser
	timeout time.Duration
	cancel  func()
}

// Returns a wrapper around the reader which obeys an idle
// timeout. The cancel function is called if the timeout happens
func newTimeoutReader(reader io.ReadCloser, timeout time.Duration, cancel func()) *timeoutReader {
	return &timeoutReader{
		reader:  reader,
		timeout: timeout,
		cancel:  cancel,
	}
}

// Read reads up to len(p) bytes into p
//
// Waits at most for timeout for the read to complete otherwise returns a timeout
func (t *timeoutReader) Read(p []byte) (int, error) {
	// FIXME limit the amount of data read in one chunk so as to not exceed the timeout?
	// Do the read in the background
	type result struct {
		n   int
		err error
	}
	done := make(chan result, 1)
	go func() {
		n, err := t.reader.Read(p)
		done <- result{n, err}
	}()
	// Wait for the read or the timeout
	select {
	case r := <-done:
		return r.n, r.err
	case <-time.After(t.timeout):
		t.cancel()
		return 0, TimeoutError
	}
	panic("unreachable") // for Go 1.0
}

// Close the channel
func (t *timeoutReader) Close() error {
	return t.reader.Close()
}

// Check it satisfies the interface
var _ io.ReadCloser = &timeoutReader{}