c4d1b34810
api client test api test one sharness test refactoring of testingData for access from other packages always wrap files added by cluster remove unused flag 'progress' changes to support hidden flag License: MIT Signed-off-by: Wyatt Daviau <wdaviau@cs.stanford.edu>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"path/filepath"
|
|
|
|
"github.com/ipfs/go-ipfs-cmdkit/files"
|
|
)
|
|
|
|
func parseFileArgs(paths []string, recursive, hidden bool) (*files.MultiFileReader, error) {
|
|
// logic largely drawn from go-ipfs-cmds/cli/parse.go: parseArgs
|
|
parsedFiles := make([]files.File, len(paths), len(paths))
|
|
for _, path := range paths {
|
|
file, err := appendFile(path, recursive, hidden)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
parsedFiles = append(parsedFiles, file)
|
|
}
|
|
|
|
sliceFile := files.NewSliceFile("", "", parsedFiles)
|
|
return files.NewMultiFileReader(sliceFile, true), nil
|
|
}
|
|
|
|
func appendFile(fpath string, recursive, hidden bool) (files.File, error) {
|
|
// logic drawn from go-ipfs-cmds/cli/parse.go: appendFile
|
|
if fpath == "." {
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cwd, err = filepath.EvalSymlinks(cwd)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
fpath = cwd
|
|
}
|
|
|
|
fpath = filepath.ToSlash(filepath.Clean(fpath))
|
|
|
|
stat, err := os.Lstat(fpath)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if stat.IsDir() {
|
|
if !recursive {
|
|
return nil, fmt.Errorf("%s is a directory, cannot add nonrecursively. Try with -r", fpath)
|
|
}
|
|
}
|
|
|
|
return files.NewSerialFile(path.Base(fpath), fpath, hidden, stat)
|
|
}
|