mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 10:27:46 +08:00
files2.0: common single-file helper
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
parent
eed806a58b
commit
351ed26bd8
@ -11,7 +11,6 @@ import (
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
|
||||
@ -154,12 +153,9 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
|
||||
return err
|
||||
}
|
||||
|
||||
it := req.Files.Entries()
|
||||
if !it.Next() && it.Err() != nil {
|
||||
return it.Err()
|
||||
}
|
||||
if files.FileFromEntry(it) == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
mhtype, _ := req.Options[mhtypeOptionName].(string)
|
||||
@ -182,7 +178,7 @@ than 'sha2-256' or format to anything other than 'v0' will result in CIDv1.
|
||||
}
|
||||
}
|
||||
|
||||
p, err := api.Block().Put(req.Context, files.FileFromEntry(it), options.Block.Hash(mhtval, mhlen), options.Block.Format(format))
|
||||
p, err := api.Block().Put(req.Context, file, options.Block.Hash(mhtval, mhlen), options.Block.Format(format))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
22
core/commands/cmdenv/file.go
Normal file
22
core/commands/cmdenv/file.go
Normal file
@ -0,0 +1,22 @@
|
||||
package cmdenv
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
)
|
||||
|
||||
func GetFileArg(it files.DirIterator) (files.File, error) {
|
||||
if !it.Next() {
|
||||
err := it.Err()
|
||||
if err == nil {
|
||||
err = fmt.Errorf("expected a file argument")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
file := files.FileFromEntry(it)
|
||||
if file == nil {
|
||||
return nil, fmt.Errorf("file argument was nil")
|
||||
}
|
||||
return file, nil
|
||||
}
|
||||
@ -10,15 +10,14 @@ import (
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
repo "github.com/ipfs/go-ipfs/repo"
|
||||
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/repo"
|
||||
"github.com/ipfs/go-ipfs/repo/fsrepo"
|
||||
|
||||
"gx/ipfs/QmP2i47tnU23ijdshrZtuvrSkQPtf9HhsMb9fwGVe8owj2/jsondiff"
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
config "gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
|
||||
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
"gx/ipfs/QmYyzmMnhNTtoXx5ttgUaRdHHckYnQWjPL98hgLAR2QLDD/go-ipfs-config"
|
||||
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
// ConfigUpdateOutput is config profile apply command's output
|
||||
@ -281,14 +280,10 @@ can't be undone.
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
it := req.Files.Entries()
|
||||
if !it.Next() && it.Err() != nil {
|
||||
return it.Err()
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if files.FileFromEntry(it) == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
}
|
||||
file := files.FileFromEntry(it)
|
||||
defer file.Close()
|
||||
|
||||
return replaceConfig(r, file)
|
||||
|
||||
@ -95,10 +95,11 @@ into an object of the specified format.
|
||||
|
||||
it := req.Files.Entries()
|
||||
for it.Next() {
|
||||
if files.FileFromEntry(it) == nil {
|
||||
file := files.FileFromEntry(it)
|
||||
if file == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
}
|
||||
nds, err := coredag.ParseInputs(ienc, format, files.FileFromEntry(it), mhType, -1)
|
||||
nds, err := coredag.ParseInputs(ienc, format, file, mhType, -1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -10,22 +10,21 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
|
||||
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
||||
"gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
||||
bservice "gx/ipfs/QmPoh3SrQzFBWtdGK6qmHDV4EanKR6kYPj4DD3J2NLoEmZ/go-blockservice"
|
||||
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
||||
mfs "gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
|
||||
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
||||
"gx/ipfs/QmU3iDRUrxyTYdV2j5MuWLFvP1k7w98vD66PLnNChgvUmZ/go-mfs"
|
||||
"gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
|
||||
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
ft "gx/ipfs/Qmbvw7kpSM2p6rbQ57WGRhhqNfCiNGW6EKH4xgHLw4bsnB/go-unixfs"
|
||||
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
|
||||
logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
|
||||
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
|
||||
)
|
||||
|
||||
@ -770,15 +769,11 @@ stat' on the file or any of its ancestors.
|
||||
return err
|
||||
}
|
||||
|
||||
it := req.Files.Entries()
|
||||
if !it.Next() && it.Err() != nil {
|
||||
return it.Err()
|
||||
var r io.Reader
|
||||
r, err = cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if files.FileFromEntry(it) == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
}
|
||||
|
||||
var r io.Reader = files.FileFromEntry(it)
|
||||
if countfound {
|
||||
r = io.LimitReader(r, int64(count))
|
||||
}
|
||||
|
||||
@ -8,16 +8,15 @@ import (
|
||||
"io/ioutil"
|
||||
"text/tabwriter"
|
||||
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
"gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
|
||||
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
ipld "gx/ipfs/QmcKKBwfz6FyQdHR2jsXrrF6XeSBXYL86anmWNewpFpoF5/go-ipld-format"
|
||||
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
@ -392,12 +391,9 @@ And then run:
|
||||
return err
|
||||
}
|
||||
|
||||
it := req.Files.Entries()
|
||||
if !it.Next() && it.Err() != nil {
|
||||
return it.Err()
|
||||
}
|
||||
if files.FileFromEntry(it) == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
inputenc, _ := req.Options["inputenc"].(string)
|
||||
@ -415,7 +411,7 @@ And then run:
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := api.Object().Put(req.Context, files.FileFromEntry(it),
|
||||
p, err := api.Object().Put(req.Context, file,
|
||||
options.Object.DataType(datafieldenc),
|
||||
options.Object.InputEnc(inputenc),
|
||||
options.Object.Pin(dopin))
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
"github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||
|
||||
"gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
@ -61,15 +60,12 @@ the limit will not be respected by the network.
|
||||
return err
|
||||
}
|
||||
|
||||
it := req.Files.Entries()
|
||||
if !it.Next() && it.Err() != nil {
|
||||
return it.Err()
|
||||
}
|
||||
if files.FileFromEntry(it) == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := api.Object().AppendData(req.Context, root, files.FileFromEntry(it))
|
||||
p, err := api.Object().AppendData(req.Context, root, file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -111,15 +107,12 @@ Example:
|
||||
return err
|
||||
}
|
||||
|
||||
it := req.Files.Entries()
|
||||
if !it.Next() && it.Err() != nil {
|
||||
return it.Err()
|
||||
}
|
||||
if files.FileFromEntry(it) == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
file, err := cmdenv.GetFileArg(req.Files.Entries())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := api.Object().SetData(req.Context, root, files.FileFromEntry(it))
|
||||
p, err := api.Object().SetData(req.Context, root, file)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -4,16 +4,15 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
core "github.com/ipfs/go-ipfs/core"
|
||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
"github.com/ipfs/go-ipfs/core"
|
||||
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||
coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||
tar "github.com/ipfs/go-ipfs/tar"
|
||||
|
||||
files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
|
||||
"gx/ipfs/QmZErC2Ay6WuGi96CPg316PwitdwgLo6RxZRqVjJjRj2MR/go-path"
|
||||
cmds "gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
"gx/ipfs/QmaAP56JAwdjwisPTu4yx17whcjTr6y5JCSCF77Y1rahWV/go-ipfs-cmds"
|
||||
dag "gx/ipfs/QmdV35UHnL1FM52baPkeUo6u7Fxm2CRUkPTLRPxeF8a4Ap/go-merkledag"
|
||||
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
"gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
|
||||
)
|
||||
|
||||
var TarCmd = &cmds.Command{
|
||||
@ -46,14 +45,12 @@ represent it.
|
||||
}
|
||||
|
||||
it := req.Files.Entries()
|
||||
if !it.Next() && it.Err() != nil {
|
||||
return it.Err()
|
||||
}
|
||||
if files.FileFromEntry(it) == nil {
|
||||
return fmt.Errorf("expected a regular file")
|
||||
file, err := cmdenv.GetFileArg(it)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
node, err := tar.ImportTar(req.Context, files.FileFromEntry(it), nd.DAG)
|
||||
node, err := tar.ImportTar(req.Context, file, nd.DAG)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -547,11 +547,8 @@ func (adder *Adder) addDir(path string, dir files.Directory) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if it.Err() != nil {
|
||||
return it.Err()
|
||||
}
|
||||
|
||||
return nil
|
||||
return it.Err()
|
||||
}
|
||||
|
||||
func (adder *Adder) maybePauseForGC() error {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user