mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
9f9ef1340c
streaming mode would create separate grpc connections for each call. this is to ensure the long poll connections are properly closed.
65 lines
1.3 KiB
Go
65 lines
1.3 KiB
Go
package shell
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"math"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
"github.com/chrislusf/seaweedfs/weed/util"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandFsCat{})
|
|
}
|
|
|
|
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
|
|
`
|
|
}
|
|
|
|
func (c *commandFsCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
path, err := commandEnv.parseUrl(findInputDirectory(args))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if commandEnv.isDirectory(path) {
|
|
return fmt.Errorf("%s is a directory", path)
|
|
}
|
|
|
|
dir, name := util.FullPath(path).DirAndName()
|
|
|
|
return commandEnv.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
|
|
|
request := &filer_pb.LookupDirectoryEntryRequest{
|
|
Name: name,
|
|
Directory: dir,
|
|
}
|
|
respLookupEntry, err := filer_pb.LookupEntry(client, request)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(respLookupEntry.Entry.Content) > 0 {
|
|
_, err = writer.Write(respLookupEntry.Entry.Content)
|
|
return err
|
|
}
|
|
|
|
return filer.StreamContent(commandEnv.MasterClient, writer, respLookupEntry.Entry.Chunks, 0, math.MaxInt64)
|
|
|
|
})
|
|
|
|
}
|