Skip to content

Commit

Permalink
coreapi: remove hidden file handling in add
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Mar 11, 2019
1 parent 3b2d568 commit 9e2b237
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 43 deletions.
22 changes: 16 additions & 6 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import (
"fmt"
"io"
"os"
"path"
"strings"

"github.com/ipfs/go-ipfs/core/commands/cmdenv"

cmdkit "github.com/ipfs/go-ipfs-cmdkit"
cmds "github.com/ipfs/go-ipfs-cmds"
coreiface "github.com/ipfs/interface-go-ipfs-core"
options "github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/go-ipfs-files"
mh "github.com/multiformats/go-multihash"
pb "gopkg.in/cheggaaa/pb.v1"
)
Expand Down Expand Up @@ -160,7 +162,7 @@ You can now check what blocks have been created by:
trickle, _ := req.Options[trickleOptionName].(bool)
wrap, _ := req.Options[wrapOptionName].(bool)
hash, _ := req.Options[onlyHashOptionName].(bool)
hidden, _ := req.Options[hiddenOptionName].(bool)
//hidden, _ := req.Options[hiddenOptionName].(bool)
silent, _ := req.Options[silentOptionName].(bool)
chunker, _ := req.Options[chunkerOptionName].(string)
dopin, _ := req.Options[pinOptionName].(bool)
Expand All @@ -186,7 +188,7 @@ You can now check what blocks have been created by:
events := make(chan interface{}, adderOutChanSize)

var toadd files.Node = req.Files
addName := ""
name := ""
if !wrap {
it := req.Files.Entries()
if !it.Next() {
Expand All @@ -197,8 +199,12 @@ You can now check what blocks have been created by:
return err
}

addName = it.Name()
toadd = it.Node()
name = it.Name()
}
_, dir := toadd.(files.Directory)
if !dir && pathName != "" {
name = pathName
}

opts := []options.UnixfsAddOption{
Expand All @@ -214,13 +220,11 @@ You can now check what blocks have been created by:
options.Unixfs.FsCache(fscache),
options.Unixfs.Nocopy(nocopy),

options.Unixfs.Hidden(hidden),
options.Unixfs.StdinName(pathName),

options.Unixfs.Progress(progress),
options.Unixfs.Silent(silent),
options.Unixfs.Events(events),
options.Unixfs.BaseName(addName),
}

if cidVerSet {
Expand Down Expand Up @@ -254,6 +258,12 @@ You can now check what blocks have been created by:
h = enc.Encode(output.Path.Cid())
}

if !dir && name != "" {
output.Name = name
} else {
output.Name = path.Join(name, output.Name)
}

res.Emit(&AddEvent{
Name: output.Name,
Hash: h,
Expand Down
3 changes: 0 additions & 3 deletions core/coreapi/unixfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,13 @@ func (api *UnixfsAPI) Add(ctx context.Context, files files.Node, opts ...options
fileAdder.Out = settings.Events
fileAdder.Progress = settings.Progress
}
fileAdder.Hidden = settings.Hidden
fileAdder.Wrap = settings.Wrap
fileAdder.Pin = settings.Pin && !settings.OnlyHash
fileAdder.Silent = settings.Silent
fileAdder.RawLeaves = settings.RawLeaves
fileAdder.NoCopy = settings.NoCopy
fileAdder.Name = settings.StdinName
fileAdder.BaseName = settings.BaseName
fileAdder.CidBuilder = prefix
fileAdder.TopHidden = settings.TopHidden

switch settings.Layout {
case options.BalancedLayout:
Expand Down
1 change: 0 additions & 1 deletion core/corehttp/gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
files "github.com/ipfs/go-ipfs-files"
path "github.com/ipfs/go-path"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/options"
nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
ci "github.com/libp2p/go-libp2p-crypto"
id "github.com/libp2p/go-libp2p/p2p/protocol/identify"
Expand Down
37 changes: 4 additions & 33 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCLocker, ds ipld.DAG
dagService: ds,
bufferedDS: bufferedDS,
Progress: false,
Hidden: true,
Pin: true,
Trickle: false,
Wrap: false,
Expand All @@ -67,15 +66,12 @@ type Adder struct {
bufferedDS *ipld.BufferedDAG
Out chan<- interface{}
Progress bool
Hidden bool
TopHidden bool
Pin bool
Trickle bool
RawLeaves bool
Silent bool
Wrap bool
Name string
BaseName string
NoCopy bool
Chunker string
root ipld.Node
Expand Down Expand Up @@ -231,9 +227,6 @@ func (adder *Adder) outputDirs(path string, fsn mfs.FSNode) error {

func (adder *Adder) addNode(node ipld.Node, path string) error {
// patch it into the root
if adder.BaseName != "" {
path = gopath.Join(adder.BaseName, path)
}
if path == "" {
path = node.Cid().String()
}
Expand Down Expand Up @@ -279,25 +272,8 @@ func (adder *Adder) AddAllAndPin(file files.Node) (ipld.Node, error) {
}
}()

d, dir := file.(files.Directory)
if !dir || !adder.TopHidden {
d = files.NewSliceDirectory([]files.DirEntry{
files.FileEntry("", file),
})
}


// Iterate over each top-level file and add individually. Otherwise the
// single files.File f is treated as a directory, affecting hidden file
// semantics.
it := d.Entries()
for it.Next() {
if err := adder.addFileNode(it.Name(), it.Node(), true); err != nil {
return nil, err
}
}
if it.Err() != nil {
return nil, it.Err()
if err := adder.addFileNode("", file, true); err != nil {
return nil, err
}

mr, err := adder.mfsRoot()
Expand All @@ -313,6 +289,7 @@ func (adder *Adder) AddAllAndPin(file files.Node) (ipld.Node, error) {
return nil, err
}

_, dir := file.(files.Directory)
var name string
if !adder.Wrap && !dir {
children, err := rootdir.ListNames(adder.ctx)
Expand Down Expand Up @@ -355,7 +332,7 @@ func (adder *Adder) AddAllAndPin(file files.Node) (ipld.Node, error) {
return nil, err
}

if err := outputDagnode(adder.Out, adder.BaseName, nd); err != nil {
if err := outputDagnode(adder.Out, "", nd); err != nil {
return nil, err
}
}
Expand Down Expand Up @@ -473,12 +450,6 @@ func (adder *Adder) addDir(path string, dir files.Directory, toplevel bool) erro
it := dir.Entries()
for it.Next() {
fpath := gopath.Join(path, it.Name())

// Skip hidden files when adding recursively, unless Hidden is enabled.
if files.IsHidden(fpath, it.Node()) && !adder.Hidden {
log.Infof("%s is hidden, skipping", fpath)
continue
}
err := adder.addFileNode(fpath, it.Node(), false)
if err != nil {
return err
Expand Down

0 comments on commit 9e2b237

Please sign in to comment.