Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Dominic Della Valle <[email protected]>
  • Loading branch information
djdv committed Apr 20, 2018
1 parent d04eb43 commit b202622
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"runtime"
"sort"
Expand Down Expand Up @@ -479,19 +478,27 @@ func appendFile(fpath string, argDef *cmdkit.Argument, recursive, hidden, travLi
}

fpath = filepath.ToSlash(filepath.Clean(fpath))

if travLinks {
fpath, err := filepath.EvalSymlinks(fpath)
if err != nil {
return nil, err
}
}
fname := filepath.Base(fpath)

stat, err := os.Lstat(fpath)
if err != nil {
return nil, err
}

if travLinks {
//deep resolve base only
for stat.Mode()&os.ModeSymlink != 0 {
fpath, err = os.Readlink(fpath)
if err != nil {
return nil, err
}
stat, err = os.Lstat(fpath)
if err != nil {
return nil, err
}
}
}

if stat.IsDir() {
if !argDef.Recursive {
return nil, fmt.Errorf(dirNotSupportedFmtStr, fpath, argDef.Name)
Expand All @@ -501,7 +508,7 @@ func appendFile(fpath string, argDef *cmdkit.Argument, recursive, hidden, travLi
}
}

return files.NewSerialFile(path.Base(fpath), fpath, hidden, stat)
return files.NewSerialFile(fname, fpath, hidden, stat)
}

// Inform the user if a file is waiting on input
Expand Down

0 comments on commit b202622

Please sign in to comment.