mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 09:34:03 +08:00
Merge pull request #2202 from noffle/hidden_files-2145
Lets 'ipfs add' include top-level hidden files
This commit is contained in:
@ -2,6 +2,7 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
||||||
"github.com/ipfs/go-ipfs/core/coreunix"
|
"github.com/ipfs/go-ipfs/core/coreunix"
|
||||||
@ -49,7 +50,7 @@ remains to be implemented.
|
|||||||
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation"),
|
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(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk"),
|
||||||
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object"),
|
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.StringOption(chunkerOptionName, "s", "chunking algorithm to use"),
|
||||||
cmds.BoolOption(pinOptionName, "Pin this object when adding. Default true"),
|
cmds.BoolOption(pinOptionName, "Pin this object when adding. Default true"),
|
||||||
},
|
},
|
||||||
@ -147,8 +148,20 @@ remains to be implemented.
|
|||||||
fileAdder.Silent = silent
|
fileAdder.Silent = silent
|
||||||
|
|
||||||
addAllAndPin := func(f files.File) error {
|
addAllAndPin := func(f files.File) error {
|
||||||
if err := fileAdder.AddFile(f); err != nil {
|
// Iterate over each top-level file and add individually. Otherwise the
|
||||||
return err
|
// 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 {
|
if hash {
|
||||||
|
@ -359,11 +359,7 @@ func (adder *Adder) addFile(file files.File) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
if file.IsDirectory() {
|
||||||
case files.IsHidden(file) && !adder.Hidden:
|
|
||||||
log.Infof("%s is hidden, skipping", file.FileName())
|
|
||||||
return &hiddenFileError{file.FileName()}
|
|
||||||
case file.IsDirectory():
|
|
||||||
return adder.addDir(file)
|
return adder.addDir(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,11 +413,13 @@ func (adder *Adder) addDir(dir files.File) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
err = adder.addFile(file)
|
// Skip hidden files when adding recursively, unless Hidden is enabled.
|
||||||
if _, ok := err.(*hiddenFileError); ok {
|
if files.IsHidden(file) && !adder.Hidden {
|
||||||
// hidden file error, skip file
|
log.Infof("%s is hidden, skipping", file.FileName())
|
||||||
continue
|
continue
|
||||||
} else if err != nil {
|
}
|
||||||
|
err = adder.addFile(file)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,17 @@ test_add_skip() {
|
|||||||
test_cmp expected actual
|
test_cmp expected actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success "'ipfs add' includes hidden files given explicitly 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
|
# should work offline
|
||||||
|
Reference in New Issue
Block a user