| 263 | } |
| 264 | |
| 265 | func (u *Upstream) writeTar(writer io.WriteCloser, stream remote.Upstream_UploadServer) error { |
| 266 | defer writer.Close() |
| 267 | |
| 268 | // Receive file |
| 269 | for { |
| 270 | chunk, err := stream.Recv() |
| 271 | if chunk != nil { |
| 272 | n, err := writer.Write(chunk.Content) |
| 273 | if err != nil { |
| 274 | // this means the tar is done already, so we just exit here |
| 275 | if strings.Contains(err.Error(), "io: read/write on closed pipe") { |
| 276 | return nil |
| 277 | } |
| 278 | |
| 279 | return err |
| 280 | } else if n != len(chunk.Content) { |
| 281 | return errors.Errorf("error writing data: bytes written %d != expected %d", n, len(chunk.Content)) |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | if err == io.EOF { |
| 286 | return nil |
| 287 | } else if err != nil { |
| 288 | return err |
| 289 | } |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | func (u *Upstream) Execute(ctx context.Context, cmd *remote.Command) (*remote.Empty, error) { |
| 294 | if cmd.Once { |