2019-04-22 06:43:43 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"math"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer2"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 16:30:24 +08:00
|
|
|
Commands = append(Commands, &commandFsCat{})
|
2019-04-22 06:43:43 +08: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
|
|
|
|
fs.cat http://<filer_server>:<port>/dir/file_name
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-04-22 06:43:43 +08:00
|
|
|
|
|
|
|
input := findInputDirectory(args)
|
|
|
|
|
|
|
|
filerServer, filerPort, path, err := commandEnv.parseUrl(input)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-26 13:50:12 +08:00
|
|
|
if commandEnv.isDirectory(filerServer, filerPort, path) {
|
2019-04-22 06:43:43 +08:00
|
|
|
return fmt.Errorf("%s is a directory", path)
|
|
|
|
}
|
|
|
|
|
|
|
|
dir, name := filer2.FullPath(path).DirAndName()
|
|
|
|
|
2020-02-26 13:50:12 +08:00
|
|
|
return commandEnv.withFilerClient(filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
|
2019-04-22 06:43:43 +08:00
|
|
|
|
|
|
|
request := &filer_pb.LookupDirectoryEntryRequest{
|
|
|
|
Name: name,
|
|
|
|
Directory: dir,
|
|
|
|
}
|
2020-03-08 08:51:46 +08:00
|
|
|
respLookupEntry, err := filer_pb.LookupEntry(client, request)
|
2019-04-22 06:43:43 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
return filer2.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt32)
|
2019-04-22 06:43:43 +08:00
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|