Skip to content

Commit

Permalink
Remove user management as folders, add user management through the mf…
Browse files Browse the repository at this point in the history
…s root
  • Loading branch information
BoThe1K committed Jan 23, 2025
1 parent 7ca448c commit d4a2610
Show file tree
Hide file tree
Showing 18 changed files with 289 additions and 486 deletions.
7 changes: 6 additions & 1 deletion cmd/ipfs/kubo/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
fsrepo "github.com/ipfs/kubo/repo/fsrepo"
"github.com/ipfs/kubo/repo/fsrepo/migrations"
"github.com/ipfs/kubo/repo/fsrepo/migrations/ipfsfetcher"
"github.com/ipfs/kubo/sds"
goprocess "github.com/jbenet/goprocess"
p2pcrypto "github.com/libp2p/go-libp2p/core/crypto"
pnet "github.com/libp2p/go-libp2p/core/pnet"
Expand Down Expand Up @@ -184,6 +185,8 @@ Headers.
cmds.BoolOption(enableMultiplexKwd, "DEPRECATED"),
cmds.StringOption(agentVersionSuffix, "Optional suffix to the AgentVersion presented by `ipfs id` and exposed via libp2p identify protocol."),

cmds.StringOption(sds.OptionSpfsUserId, "Spfs user id for user management."),

// TODO: add way to override addresses. tricky part: updating the config if also --init.
// cmds.StringOption(apiAddrKwd, "Address for the daemon rpc API (overrides config)"),
// cmds.StringOption(swarmAddrKwd, "Address for the swarm socket (overrides config)"),
Expand Down Expand Up @@ -1060,9 +1063,11 @@ func maybeRunGC(req *cmds.Request, node *core.IpfsNode) (<-chan error, error) {
return nil, nil
}

ns, _ := req.Options[sds.OptionSpfsUserId].(string)

errc := make(chan error)
go func() {
errc <- corerepo.PeriodicGC(req.Context, node)
errc <- corerepo.PeriodicGC(req.Context, node, ns)
close(errc)
}()
return errc, nil
Expand Down
6 changes: 5 additions & 1 deletion cmd/ipfs/kubo/pinmfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ type ipfsPinMFSNode struct {
}

func (x *ipfsPinMFSNode) RootNode() (ipld.Node, error) {
return x.node.FilesRoot.GetDirectory().GetNode()
filesRoot, err := x.node.GetMFSRoot("")
if err != nil {
return nil, err
}
return filesRoot.GetDirectory().GetNode()
}

func (x *ipfsPinMFSNode) Identity() peer.ID {
Expand Down
14 changes: 11 additions & 3 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ See 'dag export' and 'dag import' for more information.
cmds.UintOption(modeOptionName, "Custom POSIX file mode to store in created UnixFS entries. Disables raw-leaves. (experimental)"),
cmds.Int64Option(mtimeOptionName, "Custom POSIX modification time to store in created UnixFS entries (seconds before or after the Unix Epoch). Disables raw-leaves. (experimental)"),
cmds.UintOption(mtimeNsecsOptionName, "Custom POSIX modification time (optional time fraction in nanoseconds)"),
spfsUserIdOption,
spfsPrivKeyOption,
},
PreRun: func(req *cmds.Request, env cmds.Environment) error {
Expand Down Expand Up @@ -355,6 +356,13 @@ See 'dag export' and 'dag import' for more information.
if err != nil {
return err
}

userId, _ := req.Options[sds.OptionSpfsUserId].(string)
filesRoot, err := ipfsNode.GetMFSRoot(userId)
if err != nil {
return err
}

var added int
var fileAddedToMFS bool
addit := toadd.Entries()
Expand Down Expand Up @@ -387,7 +395,7 @@ See 'dag export' and 'dag import' for more information.
dstAsDir := toFilesDst[len(toFilesDst)-1] == '/'

if dstAsDir {
mfsNode, err := mfs.Lookup(ipfsNode.FilesRoot, toFilesDst)
mfsNode, err := mfs.Lookup(filesRoot, toFilesDst)
// confirm dst exists
if err != nil {
errCh <- fmt.Errorf("%s: MFS destination directory %q does not exist: %w", toFilesOptionName, toFilesDst, err)
Expand All @@ -408,7 +416,7 @@ See 'dag export' and 'dag import' for more information.
return
}

_, err = mfs.Lookup(ipfsNode.FilesRoot, gopath.Dir(toFilesDst))
_, err = mfs.Lookup(filesRoot, gopath.Dir(toFilesDst))
if err != nil {
errCh <- fmt.Errorf("%s: MFS destination parent %q %q does not exist: %w", toFilesOptionName, toFilesDst, gopath.Dir(toFilesDst), err)
return
Expand All @@ -420,7 +428,7 @@ See 'dag export' and 'dag import' for more information.
errCh <- err
return
}
err = mfs.PutNode(ipfsNode.FilesRoot, toFilesDst, nodeAdded)
err = mfs.PutNode(filesRoot, toFilesDst, nodeAdded)
if err != nil {
errCh <- fmt.Errorf("%s: cannot put node in path %q: %w", toFilesOptionName, toFilesDst, err)
return
Expand Down
Loading

0 comments on commit d4a2610

Please sign in to comment.