diff --git a/http.go b/http.go index d8d0154e..0ab4ad31 100644 --- a/http.go +++ b/http.go @@ -2,12 +2,16 @@ package main import ( "context" + "fmt" + "os" ipfshttp "github.com/ipfs/kubo/client/rpc" iface "github.com/ipfs/kubo/core/coreiface" ) func http(ctx context.Context) (iface.CoreAPI, error) { + fmt.Fprint(os.Stderr, "Downloading from local daemon... ") + httpAPI, err := ipfshttp.NewLocalApi() if err != nil { return nil, err diff --git a/main.go b/main.go index 1536423d..698ddb1b 100644 --- a/main.go +++ b/main.go @@ -85,6 +85,9 @@ func main() { if errors.Is(err, context.Canceled) { os.Exit(2) } + if errors.Is(err, context.DeadlineExceeded) { + err = errors.New("timed out") + } fmt.Fprintln(os.Stderr, err) os.Exit(1) } @@ -113,6 +116,7 @@ func ipgetAction(ctx context.Context, cmd *cli.Command) error { case "fallback": ipfs, err = http(ctx) if err != nil { + fmt.Fprintln(os.Stderr, "failed") ipfs, err = spawn(ctx) } case "spawn": @@ -125,6 +129,7 @@ func ipgetAction(ctx context.Context, cmd *cli.Command) error { return fmt.Errorf("no such 'node' strategy, %q", cmd.String("node")) } if err != nil { + fmt.Fprintln(os.Stderr, "failed") return err } @@ -132,8 +137,11 @@ func ipgetAction(ctx context.Context, cmd *cli.Command) error { out, err := ipfs.Unixfs().Get(ctx, iPath) if err != nil { + fmt.Fprintln(os.Stderr, "failed") return err } + fmt.Fprintln(os.Stderr, "succeeded") + if err = WriteTo(out, outPath, cmd.Bool("progress")); err != nil { return err } @@ -204,7 +212,12 @@ func WriteTo(nd files.Node, fpath string, progress bool) error { bar = pb.New64(s).Start() } - return writeToRec(nd, fpath, bar) + if err = writeToRec(nd, fpath, bar); err != nil { + return err + } + + fmt.Fprintf(os.Stderr, "Saved to %s [%d bytes]\n", fpath, s) + return nil } func writeToRec(nd files.Node, fpath string, bar *pb.ProgressBar) error { diff --git a/node.go b/node.go index ab189780..73d38398 100644 --- a/node.go +++ b/node.go @@ -20,6 +20,8 @@ import ( type CfgOpt func(*config.Config) func spawn(ctx context.Context) (iface.CoreAPI, error) { + fmt.Fprint(os.Stderr, "Downloading from IPFS node with existing repo... ") + defaultPath, err := config.PathRoot() if err != nil { // shouldn't be possible @@ -32,6 +34,7 @@ func spawn(ctx context.Context) (iface.CoreAPI, error) { ipfs, err := open(ctx, defaultPath) if err != nil { + fmt.Fprintln(os.Stderr, "failed") return tmpNode(ctx) } @@ -91,6 +94,8 @@ func temp(ctx context.Context) (iface.CoreAPI, error) { } func tmpNode(ctx context.Context) (iface.CoreAPI, error) { + fmt.Fprint(os.Stderr, "Downloading from IPFS node with temporary repo... ") + dir, err := os.MkdirTemp("", "ipfs-shell") if err != nil { return nil, fmt.Errorf("failed to get temp dir: %s", err)