func New(c *tlc.Container, basePath string) (wsync.Pool, error) { if basePath == "/dev/null" { return fspool.New(c, basePath), nil } fr, err := eos.Open(basePath) if err != nil { return nil, errors.Wrap(err, 1) } targetInfo, err := fr.Stat() if err != nil { return nil, errors.Wrap(err, 1) } if targetInfo.IsDir() { err := fr.Close() if err != nil { return nil, err } return fspool.New(c, basePath), nil } else { zr, err := zip.NewReader(fr, targetInfo.Size()) if err != nil { return nil, errors.Wrap(err, 1) } return zippool.New(c, zr), nil } }
func (ah *ArchiveHealer) heal(container *tlc.Container, zipReader *zip.Reader, zipSize int64, targetPool wsync.WritablePool, fileIndices chan int64, errs chan error, done chan bool, cancelled chan struct{}, chunkHealed chunkHealedFunc) { var sourcePool wsync.Pool var err error sourcePool = zippool.New(container, zipReader) defer sourcePool.Close() for { select { case <-cancelled: // something else stopped the healing return case fileIndex, ok := <-fileIndices: if !ok { // no more files to heal done <- true return } err = ah.healOne(sourcePool, targetPool, fileIndex, chunkHealed) if err != nil { select { case <-cancelled: // already cancelled, no need for more errors return case errs <- err: return } } } } }