Skip to content

Commit 4263ae6

Browse files
authored
Merge pull request #96 from djdv/feat/resolve-links
Add link traversal option
2 parents 9e804ce + be09a40 commit 4263ae6

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

cli/parse.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ import (
1010
"sort"
1111
"strings"
1212

13-
"github.com/ipfs/go-ipfs-cmds"
14-
1513
osh "github.com/Kubuxu/go-os-helper"
1614
"github.com/ipfs/go-ipfs-cmdkit"
15+
"github.com/ipfs/go-ipfs-cmds"
1716
"github.com/ipfs/go-ipfs-files"
1817
logging "github.com/ipfs/go-log"
1918
)
@@ -265,6 +264,12 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
265264
fpath = stdin.Name()
266265
file = files.NewReaderFile("", fpath, r, nil)
267266
} else {
267+
if derefArgs, _ := req.Options[cmds.DerefLong].(bool); derefArgs {
268+
var err error // don't shadow fpath
269+
if fpath, err = filepath.EvalSymlinks(fpath); err != nil {
270+
return err
271+
}
272+
}
268273
nf, err := appendFile(fpath, argDef, isRecursive(req), isHidden(req))
269274
if err != nil {
270275
return err

opts.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const (
1414
TimeoutOpt = "timeout"
1515
OptShortHelp = "h"
1616
OptLongHelp = "help"
17+
DerefLong = "dereference-args"
1718
)
1819

1920
// options that are used by this package
2021
var OptionEncodingType = cmdkit.StringOption(EncLong, EncShort, "The encoding type the output should be encoded with (json, xml, or text)").WithDefault("text")
21-
var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory paths recursively").WithDefault(false)
22+
var OptionRecursivePath = cmdkit.BoolOption(RecLong, RecShort, "Add directory paths recursively")
2223
var OptionStreamChannels = cmdkit.BoolOption(ChanOpt, "Stream channel output")
23-
var OptionTimeout = cmdkit.StringOption(TimeoutOpt, "set a global timeout on the command")
24+
var OptionTimeout = cmdkit.StringOption(TimeoutOpt, "Set a global timeout on the command")
25+
var OptionDerefArgs = cmdkit.BoolOption(DerefLong, "Symlinks supplied in arguments are dereferenced")

0 commit comments

Comments
 (0)