Commit aa47006f authored by rht's avatar rht

serialfile: localize os.Open into NewSerialFile

License: MIT
Signed-off-by: default avatarrht <rhtbot@gmail.com>
parent 2966aa62
......@@ -356,21 +356,6 @@ func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recur
return nil, nil, err
}
if stat.Mode()&os.ModeSymlink != 0 {
target, err := os.Readlink(fpath)
if err != nil {
return nil, nil, err
}
arg := files.NewLinkFile("", fpath, target, stat)
return append(args, arg), inputs[1:], nil
}
file, err := os.Open(fpath)
if err != nil {
return nil, nil, err
}
if stat.IsDir() {
if !argDef.Recursive {
err = fmt.Errorf("Invalid path '%s', argument '%s' does not support directories",
......@@ -384,7 +369,7 @@ func appendFile(args []files.File, inputs []string, argDef *cmds.Argument, recur
}
}
arg, err := files.NewSerialFile(path.Base(fpath), fpath, file)
arg, err := files.NewSerialFile(path.Base(fpath), fpath, stat)
if err != nil {
return nil, nil, err
}
......
......@@ -25,8 +25,17 @@ type serialFile struct {
current *os.File
}
func NewSerialFile(name, path string, file *os.File) (File, error) {
stat, err := file.Stat()
func NewSerialFile(name, path string, stat os.FileInfo) (File, error) {
if stat.Mode()&os.ModeSymlink != 0 {
target, err := os.Readlink(path)
if err != nil {
return nil, err
}
return NewLinkFile("", path, target, stat), nil
}
file, err := os.Open(path)
if err != nil {
return nil, err
}
......@@ -49,8 +58,7 @@ func newSerialFile(name, path string, file *os.File, stat os.FileInfo) (File, er
// we no longer need our root directory file (we already statted the contents),
// so close it
err = file.Close()
if err != nil {
if err := file.Close(); err != nil {
return nil, err
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment