Skip to content

Commit

Permalink
Lets 'ipfs add' include top-level hidden files.
Browse files Browse the repository at this point in the history
Fixes ipfs/go-ipfs/ipfs#2145. The --hidden switch (still) only affects
recursive adding.

License: MIT
Signed-off-by: Stephen Whitmore <noffle@ipfs.io>
  • Loading branch information
hackergrrl committed Jan 14, 2016
1 parent c242660 commit 15554b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
19 changes: 16 additions & 3 deletions core/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"io"

"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/cheggaaa/pb"
"github.com/ipfs/go-ipfs/core/coreunix"
Expand Down Expand Up @@ -49,7 +50,7 @@ remains to be implemented.
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation"),
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk"),
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"),
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden"),
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
cmds.StringOption(chunkerOptionName, "s", "chunking algorithm to use"),
cmds.BoolOption(pinOptionName, "Pin this object when adding. Default true"),
},
Expand Down Expand Up @@ -147,8 +148,20 @@ remains to be implemented.
fileAdder.Silent = silent

addAllAndPin := func(f files.File) error {
if err := fileAdder.AddFile(f); err != nil {
return err
// Iterate over each top-level file and add individually. Otherwise the
// single files.File f is treated as a directory, affecting hidden file
// semantics.
for {
file, err := f.NextFile()
if err == io.EOF {
// Finished the list of files.
break
} else if err != nil {
return err
}
if err := fileAdder.AddFile(file); err != nil {
return err
}
}

if hash {
Expand Down
16 changes: 7 additions & 9 deletions core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,7 @@ func (adder *Adder) addFile(file files.File) error {
return err
}

switch {
case files.IsHidden(file) && !adder.Hidden:
log.Infof("%s is hidden, skipping", file.FileName())
return &hiddenFileError{file.FileName()}
case file.IsDirectory():
if file.IsDirectory() {
return adder.addDir(file)
}

Expand Down Expand Up @@ -417,11 +413,13 @@ func (adder *Adder) addDir(dir files.File) error {
break
}

err = adder.addFile(file)
if _, ok := err.(*hiddenFileError); ok {
// hidden file error, skip file
// Skip hidden files when adding recursively, unless Hidden is enabled.
if files.IsHidden(file) && !adder.Hidden {
log.Infof("%s is hidden, skipping", file.FileName())
continue
} else if err != nil {
}
err = adder.addFile(file)
if err != nil {
return err
}
}
Expand Down
11 changes: 11 additions & 0 deletions test/sharness/t0042-add-skip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ test_add_skip() {
test_cmp expected actual
'

test_expect_success "'ipfs add' includes hidden files at the top-level even without --hidden" '
mkdir -p mountdir/dotfiles &&
echo "set nocompatible" > mountdir/dotfiles/.vimrc
cat >expected <<-\EOF &&
added QmT4uMRDCN7EMpFeqwvKkboszbqeW1kWVGrBxBuCGqZcQc .vimrc
EOF
ipfs add mountdir/dotfiles/.vimrc >actual
cat actual
test_cmp expected actual
'

}

# should work offline
Expand Down

0 comments on commit 15554b1

Please sign in to comment.