Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Unixfs1.5 mode and modification time support #150

Merged
merged 19 commits into from
Sep 12, 2024
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
204 changes: 114 additions & 90 deletions go.mod

Large diffs are not rendered by default.

627 changes: 270 additions & 357 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package main
import (
"context"

iface "github.com/ipfs/boxo/coreiface"
ipfshttp "github.com/ipfs/kubo/client/rpc"
iface "github.com/ipfs/kubo/core/coreiface"
)

func http(ctx context.Context) (iface.CoreAPI, error) {
Expand Down
47 changes: 32 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"os/signal"
gopath "path"
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"

"github.com/cheggaaa/pb/v3"
iface "github.com/ipfs/boxo/coreiface"
ipath "github.com/ipfs/boxo/coreiface/path"
files "github.com/ipfs/boxo/files"
ipath "github.com/ipfs/boxo/path"
iface "github.com/ipfs/kubo/core/coreiface"
cli "github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -166,25 +167,28 @@ func movePostfixOptions(args []string) []string {
}

func parsePath(path string) (ipath.Path, error) {
ipfsPath := ipath.New(path)
if ipfsPath.IsValid() == nil {
ipfsPath, err := ipath.NewPath(path)
if err == nil {
return ipfsPath, nil
}
origErr := err

ipfsPath, err = ipath.NewPath("/ipfs/" + path)
if err == nil {
return ipfsPath, nil
}

u, err := url.Parse(path)
if err != nil {
return nil, fmt.Errorf("%q could not be parsed: %s", path, err)
return nil, origErr
}

switch proto := u.Scheme; proto {
switch u.Scheme {
case "ipfs", "ipld", "ipns":
ipfsPath = ipath.New(gopath.Join("/", proto, u.Host, u.Path))
return ipath.NewPath(gopath.Join("/", u.Scheme, u.Host, u.Path))
case "http", "https":
ipfsPath = ipath.New(u.Path)
default:
return nil, fmt.Errorf("%q is not recognized as an IPFS path", path)
return ipath.NewPath(u.Path)
}
return ipfsPath, ipfsPath.IsValid()
return nil, fmt.Errorf("%q is not recognized as an IPFS path", path)
}

// WriteTo writes the given node to the local filesystem at fpath.
Expand All @@ -205,7 +209,16 @@ func WriteTo(nd files.Node, fpath string, progress bool) error {
func writeToRec(nd files.Node, fpath string, bar *pb.ProgressBar) error {
switch nd := nd.(type) {
case *files.Symlink:
return os.Symlink(nd.Target, fpath)
err := os.Symlink(nd.Target, fpath)
if err != nil {
return err
}
switch runtime.GOOS {
case "linux", "freebsd", "netbsd", "openbsd", "dragonfly":
return files.UpdateModTime(fpath, nd.ModTime())
default:
return nil
}
case files.File:
f, err := os.Create(fpath)
defer f.Close()
Expand All @@ -221,20 +234,24 @@ func writeToRec(nd files.Node, fpath string, bar *pb.ProgressBar) error {
if err != nil {
return err
}
return nil
return files.UpdateMeta(fpath, nd.Mode(), nd.ModTime())
case files.Directory:
err := os.Mkdir(fpath, 0777)
if err != nil {
return err
}

entries := nd.Entries()
for entries.Next() {
child := filepath.Join(fpath, entries.Name())
if err := writeToRec(entries.Node(), child, bar); err != nil {
return err
}
}

if err = files.UpdateMeta(fpath, nd.Mode(), nd.ModTime()); err != nil {
return err
}

return entries.Err()
default:
return fmt.Errorf("file type %T at %q is not supported", nd, fpath)
Expand Down
4 changes: 2 additions & 2 deletions node.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"os"
"path/filepath"

iface "github.com/ipfs/boxo/coreiface"
"github.com/ipfs/boxo/coreiface/options"
config "github.com/ipfs/kubo/config"
"github.com/ipfs/kubo/core"
"github.com/ipfs/kubo/core/coreapi"
iface "github.com/ipfs/kubo/core/coreiface"
"github.com/ipfs/kubo/core/coreiface/options"
"github.com/ipfs/kubo/core/node/libp2p"
"github.com/ipfs/kubo/plugin/loader"
"github.com/ipfs/kubo/repo/fsrepo"
Expand Down
Loading
Loading