func restoreCache(src string, s storage.Storage, a archive.Archive) error { reader, writer := io.Pipe() cw := make(chan error, 1) defer close(cw) go func() { defer writer.Close() cw <- s.Get(src, writer) }() err := a.Unpack("", reader) werr := <-cw if werr != nil { return werr } return err }
func rebuildCache(srcs []string, dst string, s storage.Storage, a archive.Archive) error { log.Infof("Rebuilding cache at %s to %s", srcs, dst) reader, writer := io.Pipe() defer reader.Close() cw := make(chan error, 1) defer close(cw) go func() { defer writer.Close() cw <- a.Pack(srcs, writer) }() err := s.Put(dst, reader) werr := <-cw if werr != nil { return werr } return err }