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

Named pins & pins stored in datastore #4757

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion assets/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
}
}

if err := api.Pin().Add(nd.Context(), basePath); err != nil {
if err := api.Pin().Add(nd.Context(), "assets", basePath); err != nil {
return cid.Cid{}, err
}

return basePath.Cid(), nil

}
4 changes: 4 additions & 0 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
onlyHashOptionName = "only-hash"
chunkerOptionName = "chunker"
pinOptionName = "pin"
pinPathOptionName = "pinpath"
rawLeavesOptionName = "raw-leaves"
noCopyOptionName = "nocopy"
fstoreCacheOptionName = "fscache"
Expand Down Expand Up @@ -133,6 +134,7 @@ only-hash, and progress/status related flags) will change the final hash.
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm, size-[bytes], rabin-[min]-[avg]-[max] or buzhash").WithDefault("size-262144"),
cmds.BoolOption(pinOptionName, "Pin this object when adding.").WithDefault(true),
cmds.StringOption(pinPathOptionName, "P", "Pin object under this path.").WithDefault("added/"),
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
cmds.BoolOption(noCopyOptionName, "Add the file using filestore. Implies raw-leaves. (experimental)"),
cmds.BoolOption(fstoreCacheOptionName, "Check the filestore for pre-existing blocks. (experimental)"),
Expand Down Expand Up @@ -173,6 +175,7 @@ only-hash, and progress/status related flags) will change the final hash.
silent, _ := req.Options[silentOptionName].(bool)
chunker, _ := req.Options[chunkerOptionName].(string)
dopin, _ := req.Options[pinOptionName].(bool)
pinPath, _ := req.Options[pinPathOptionName].(string)
rawblks, rbset := req.Options[rawLeavesOptionName].(bool)
nocopy, _ := req.Options[noCopyOptionName].(bool)
fscache, _ := req.Options[fstoreCacheOptionName].(bool)
Expand Down Expand Up @@ -207,6 +210,7 @@ only-hash, and progress/status related flags) will change the final hash.
options.Unixfs.Chunker(chunker),

options.Unixfs.Pin(dopin),
options.Unixfs.PinPath(pinPath),
options.Unixfs.HashOnly(hash),
options.Unixfs.FsCache(fscache),
options.Unixfs.Nocopy(nocopy),
Expand Down
22 changes: 10 additions & 12 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ into an object of the specified format.
Options: []cmds.Option{
cmds.StringOption("format", "f", "Format that the object will be added as.").WithDefault("cbor"),
cmds.StringOption("input-enc", "Format that the input object will be.").WithDefault("json"),
cmds.BoolOption("pin", "Pin this object when adding."),
cmds.StringOption("pin", "Pin this object when adding.").WithDefault(""),
cmds.StringOption("hash", "Hash function to use").WithDefault(""),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
Expand All @@ -106,7 +106,7 @@ into an object of the specified format.
ienc, _ := req.Options["input-enc"].(string)
format, _ := req.Options["format"].(string)
hash, _ := req.Options["hash"].(string)
dopin, _ := req.Options["pin"].(bool)
pinpath, _ := req.Options["pin"].(string)

// mhType tells inputParser which hash should be used. MaxUint64 means 'use
// default hash' (sha256 for cbor, sha1 for git..)
Expand All @@ -121,9 +121,6 @@ into an object of the specified format.
}

var adder ipld.NodeAdder = api.Dag()
if dopin {
adder = api.Dag().Pinning()
}
b := ipld.NewBatch(req.Context, adder)

it := req.Files.Entries()
Expand All @@ -140,10 +137,13 @@ into an object of the specified format.
return fmt.Errorf("no node returned from ParseInputs")
}

for _, nd := range nds {
err := b.Add(req.Context, nd)
if err != nil {
return err
if pinpath != "" {

for _, nd := range nds {
err := api.Pin().Add(req.Context, pinpath, path.IpfsPath(nd.Cid()))
if err != nil {
return err
}
}
}

Expand Down Expand Up @@ -387,9 +387,7 @@ Maximum supported CAR version: 1
ret.PinErrorMsg = err.Error()
} else if nd, err := ipld.Decode(block); err != nil {
ret.PinErrorMsg = err.Error()
} else if err := node.Pinning.Pin(req.Context, nd, true); err != nil {
ret.PinErrorMsg = err.Error()
} else if err := node.Pinning.Flush(req.Context); err != nil {
} else if err := node.Pinning.Pin(req.Context, "car-import/", nd, true); err != nil {
ret.PinErrorMsg = err.Error()
}

Expand Down
11 changes: 9 additions & 2 deletions core/commands/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ And then run:
cmds.StringOption(datafieldencOptionName, "Encoding type of the data field, either \"text\" or \"base64\".").WithDefault("text"),
cmds.BoolOption(pinOptionName, "Pin this object when adding."),
cmds.BoolOption(quietOptionName, "q", "Write minimal output."),
cmds.StringOption("pinpath", "Pin under this path").WithDefault("added/"),
},
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
api, err := cmdenv.GetApi(env, req)
Expand Down Expand Up @@ -431,15 +432,21 @@ And then run:
return err
}

dopin, _ := req.Options[pinOptionName].(bool)
pinpath, _ := req.Options["pinpath"].(string)
if err != nil {
return err
}

pin, _ := req.Options["pin"].(bool)
if err != nil {
return err
}

p, err := api.Object().Put(req.Context, file,
options.Object.DataType(datafieldenc),
options.Object.InputEnc(inputenc),
options.Object.Pin(dopin))
options.Object.Pin(pin),
options.Object.PinPath(pinpath))
if err != nil {
return err
}
Expand Down
Loading