mirror of
https://github.com/gomods/athens
synced 2026-02-03 14:20:31 +00:00
* switch proxy to config file pull in single flight changes * changes for single-flight * intermediate stage. All tests passing. pkg still has env refs * remove all env references * delete config/env entirely * fix failing tests * create the config.toml file as part of dev setup * create config file only if it doesn't exist * update Dockerfiles to use config file * move composing elements to the top * verbose parameter naming * newline * add flag for config file path * update docs with config file flag * remove unnecessary nil check * use filepath.join * rename redis port to address * fix path.join * fix issues after merge * add vendor dir
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package module
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/gomods/athens/pkg/config"
|
|
"github.com/gomods/athens/pkg/errors"
|
|
multierror "github.com/hashicorp/go-multierror"
|
|
)
|
|
|
|
// Deleter takes a path to a file and deletes it from the blob store
|
|
type Deleter func(ctx context.Context, path string) error
|
|
|
|
// Delete deletes .info, .mod and .zip files from the blob store in parallel.
|
|
// Returns multierror containing errors from all deletes and timeouts
|
|
func Delete(ctx context.Context, module, version string, delete Deleter, timeout time.Duration) error {
|
|
const op errors.Op = "module.Delete"
|
|
tctx, cancel := context.WithTimeout(ctx, timeout)
|
|
defer cancel()
|
|
|
|
del := func(ext string) <-chan error {
|
|
ec := make(chan error)
|
|
|
|
go func() {
|
|
defer close(ec)
|
|
p := config.PackageVersionedName(module, version, ext)
|
|
ec <- delete(tctx, p)
|
|
}()
|
|
return ec
|
|
}
|
|
|
|
errChan := make(chan error, numFiles)
|
|
delOrAbort := func(ext string) {
|
|
select {
|
|
case err := <-del(ext):
|
|
errChan <- err
|
|
case <-tctx.Done():
|
|
errChan <- fmt.Errorf("deleting %s.%s.%s failed: %s", module, version, ext, tctx.Err())
|
|
}
|
|
}
|
|
|
|
go delOrAbort("info")
|
|
go delOrAbort("mod")
|
|
go delOrAbort("zip")
|
|
|
|
var errs error
|
|
for i := 0; i < numFiles; i++ {
|
|
err := <-errChan
|
|
if err != nil {
|
|
errs = multierror.Append(errs, err)
|
|
}
|
|
}
|
|
close(errChan)
|
|
if errs != nil {
|
|
return errors.E(op, errs)
|
|
}
|
|
return nil
|
|
}
|