| 242 | } |
| 243 | |
| 244 | func (s *Sync) syncOutgoingAdds(adds []changes.Change, st Stream) { |
| 245 | if len(adds) == 0 { |
| 246 | return |
| 247 | } |
| 248 | |
| 249 | var buf bytes.Buffer |
| 250 | |
| 251 | tgz := tar.NewWriter(&buf) |
| 252 | |
| 253 | for _, a := range adds { |
| 254 | local := filepath.Join(a.Base, a.Path) |
| 255 | |
| 256 | info, err := os.Stat(local) |
| 257 | if err != nil { |
| 258 | continue |
| 259 | } |
| 260 | |
| 261 | remote := filepath.Join(s.Remote, a.Path) |
| 262 | |
| 263 | s.lock.Lock() |
| 264 | s.incomingBlocks[a.Path]++ |
| 265 | s.lock.Unlock() |
| 266 | |
| 267 | tgz.WriteHeader(&tar.Header{ |
| 268 | Name: remote, |
| 269 | Mode: 0644, |
| 270 | Size: info.Size(), |
| 271 | ModTime: info.ModTime(), |
| 272 | }) |
| 273 | |
| 274 | fd, err := os.Open(local) |
| 275 | |
| 276 | if err != nil { |
| 277 | st <- fmt.Sprintf("error: %s", err) |
| 278 | continue |
| 279 | } |
| 280 | |
| 281 | io.Copy(tgz, fd) |
| 282 | fd.Close() |
| 283 | } |
| 284 | |
| 285 | st <- fmt.Sprintf("%d files uploaded", len(adds)) |
| 286 | |
| 287 | if os.Getenv("CONVOX_DEBUG") != "" { |
| 288 | for _, a := range adds { |
| 289 | st <- fmt.Sprintf("%s -> %s:%s", filepath.Join(a.Base, a.Path), s.Container, filepath.Join(s.Remote, a.Path)) |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | tgz.Close() |
| 294 | |
| 295 | err := s.docker.UploadToContainer(s.Container, docker.UploadToContainerOptions{ |
| 296 | InputStream: &buf, |
| 297 | Path: "/", |
| 298 | }) |
| 299 | |
| 300 | if err != nil { |
| 301 | st <- fmt.Sprintf("error: %s", err) |