Skip to content
This repository was archived by the owner on Aug 4, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions http.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand Down
15 changes: 14 additions & 1 deletion main.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
}
Expand DownExpand Up@@ -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":
Expand All@@ -125,15 +129,19 @@ 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
}

go connect(ctx, ipfs, cmd.StringSlice("peers"))

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
}
Expand DownExpand Up@@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions node.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
Expand All@@ -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)
}

Expand DownExpand Up@@ -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)
Expand Down
Loading