2019-04-21 22:43:43 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"math"
|
|
|
|
|
2020-09-01 07:21:19 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
2019-04-21 22:43:43 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2020-03-23 07:01:34 +00:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
2019-04-21 22:43:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 08:30:24 +00:00
|
|
|
Commands = append(Commands, &commandFsCat{})
|
2019-04-21 22:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type commandFsCat struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsCat) Name() string {
|
|
|
|
return "fs.cat"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsCat) Help() string {
|
|
|
|
return `stream the file content on to the screen
|
|
|
|
|
|
|
|
fs.cat /dir/file_name
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2019-06-05 08:30:24 +00:00
|
|
|
func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-04-21 22:43:43 +00:00
|
|
|
|
2020-03-24 04:26:15 +00:00
|
|
|
path, err := commandEnv.parseUrl(findInputDirectory(args))
|
2019-04-21 22:43:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-03-24 04:26:15 +00:00
|
|
|
if commandEnv.isDirectory(path) {
|
2019-04-21 22:43:43 +00:00
|
|
|
return fmt.Errorf("%s is a directory", path)
|
|
|
|
}
|
|
|
|
|
2020-03-23 07:01:34 +00:00
|
|
|
dir, name := util.FullPath(path).DirAndName()
|
2019-04-21 22:43:43 +00:00
|
|
|
|
2020-03-24 04:26:15 +00:00
|
|
|
return commandEnv.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
2019-04-21 22:43:43 +00:00
|
|
|
|
|
|
|
request := &filer_pb.LookupDirectoryEntryRequest{
|
|
|
|
Name: name,
|
|
|
|
Directory: dir,
|
|
|
|
}
|
2020-03-08 00:51:46 +00:00
|
|
|
respLookupEntry, err := filer_pb.LookupEntry(client, request)
|
2019-04-21 22:43:43 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-05 22:11:39 +00:00
|
|
|
return filer.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt64)
|
2019-04-21 22:43:43 +00:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|