helpers.go 692 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "os"
  4. "os/signal"
  5. "path/filepath"
  6. "syscall"
  7. "github.com/pkg/errors"
  8. )
  9. func fetchFullBareRepo(root string) (string, error) {
  10. // TODO: get host from envvar
  11. tmpPath := filepath.Join("/", os.TempDir(), root)
  12. _, err := os.Stat(tmpPath)
  13. switch {
  14. case os.IsNotExist(err) || err == nil:
  15. if err := ipfsShell.Get(root, tmpPath); err != nil {
  16. return "", errors.Wrapf(err, "shell.Get(%s, %s) failed: %s", root, tmpPath, err)
  17. }
  18. return tmpPath, nil
  19. default:
  20. return "", errors.Wrap(err, "os.Stat(): unhandled error")
  21. }
  22. }
  23. func interrupt() error {
  24. c := make(chan os.Signal)
  25. signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
  26. return errors.Errorf("%s", <-c)
  27. }