newUpstream creates a new upstream handler with the given parameters
(reader io.ReadCloser, writer io.WriteCloser, sync *Sync)
| 69 | |
| 70 | // newUpstream creates a new upstream handler with the given parameters |
| 71 | func newUpstream(reader io.ReadCloser, writer io.WriteCloser, sync *Sync) (*upstream, error) { |
| 72 | var ( |
| 73 | clientReader io.Reader = reader |
| 74 | clientWriter io.Writer = writer |
| 75 | ) |
| 76 | |
| 77 | // Apply limits if specified |
| 78 | if sync.Options.DownstreamLimit > 0 { |
| 79 | limitedReader := shapeio.NewReader(reader) |
| 80 | limitedReader.SetRateLimit(float64(sync.Options.DownstreamLimit)) |
| 81 | clientReader = limitedReader |
| 82 | } |
| 83 | if sync.Options.UpstreamLimit > 0 { |
| 84 | limitedWriter := shapeio.NewWriter(writer) |
| 85 | limitedWriter.SetRateLimit(float64(sync.Options.UpstreamLimit)) |
| 86 | clientWriter = limitedWriter |
| 87 | } |
| 88 | |
| 89 | // Create client |
| 90 | conn, err := util.NewClientConnection(clientReader, clientWriter) |
| 91 | if err != nil { |
| 92 | return nil, errors.Wrap(err, "new client connection") |
| 93 | } |
| 94 | |
| 95 | // Create combined exclude paths |
| 96 | excludePaths := make([]string, 0, len(sync.Options.ExcludePaths)+len(sync.Options.UploadExcludePaths)) |
| 97 | excludePaths = append(excludePaths, sync.Options.ExcludePaths...) |
| 98 | excludePaths = append(excludePaths, sync.Options.UploadExcludePaths...) |
| 99 | |
| 100 | ignoreMatcher, err := ignoreparser.CompilePaths(excludePaths, sync.log) |
| 101 | if err != nil { |
| 102 | return nil, errors.Wrap(err, "compile paths") |
| 103 | } |
| 104 | |
| 105 | return &upstream{ |
| 106 | events: make(chan notify.EventInfo, 1000), // High buffer size so we don't miss any fsevents if there are a lot of changes |
| 107 | eventBuffer: make([]notify.EventInfo, 0, 64), |
| 108 | symlinks: make(map[string]*Symlink), |
| 109 | sync: sync, |
| 110 | isBusy: true, |
| 111 | |
| 112 | reader: reader, |
| 113 | writer: writer, |
| 114 | client: remote.NewUpstreamClient(conn), |
| 115 | |
| 116 | ignoreMatcher: ignoreMatcher, |
| 117 | |
| 118 | conn: conn, |
| 119 | }, nil |
| 120 | } |
| 121 | |
| 122 | func (u *upstream) IsBusy() bool { |
| 123 | u.isBusyMutex.Lock() |
no test coverage detected