aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_fs_meta_cat.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2019-12-20 08:22:18 -0800
committerChris Lu <chris.lu@gmail.com>2019-12-20 08:22:18 -0800
commitd0aa0c50864d2c1473f0918614c66351297bd579 (patch)
treea21f108b95db5841de79985aef3d625d903954fc /weed/shell/command_fs_meta_cat.go
parentab966d7192a02538737eb6515ce4192139e9b410 (diff)
downloadseaweedfs-d0aa0c50864d2c1473f0918614c66351297bd579.tar.xz
seaweedfs-d0aa0c50864d2c1473f0918614c66351297bd579.zip
shell: add fs.meta.cat to see file meta data content
related to https://github.com/chrislusf/seaweedfs/issues/1163
Diffstat (limited to 'weed/shell/command_fs_meta_cat.go')
-rw-r--r--weed/shell/command_fs_meta_cat.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/weed/shell/command_fs_meta_cat.go b/weed/shell/command_fs_meta_cat.go
new file mode 100644
index 000000000..5908b0a3c
--- /dev/null
+++ b/weed/shell/command_fs_meta_cat.go
@@ -0,0 +1,75 @@
+package shell
+
+import (
+ "context"
+ "fmt"
+ "io"
+
+ "github.com/golang/protobuf/jsonpb"
+
+ "github.com/chrislusf/seaweedfs/weed/filer2"
+ "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+)
+
+func init() {
+ Commands = append(Commands, &commandFsMetaCat{})
+}
+
+type commandFsMetaCat struct {
+}
+
+func (c *commandFsMetaCat) Name() string {
+ return "fs.meta.cat"
+}
+
+func (c *commandFsMetaCat) Help() string {
+ return `print out the meta data content for a file or directory
+
+ fs.meta.cat /dir/
+ fs.meta.cat /dir/file_name
+ fs.meta.cat http://<filer_server>:<port>/dir/
+ fs.meta.cat http://<filer_server>:<port>/dir/file_name
+`
+}
+
+func (c *commandFsMetaCat) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
+
+ input := findInputDirectory(args)
+
+ filerServer, filerPort, path, err := commandEnv.parseUrl(input)
+ if err != nil {
+ return err
+ }
+
+ ctx := context.Background()
+
+ dir, name := filer2.FullPath(path).DirAndName()
+
+ return commandEnv.withFilerClient(ctx, filerServer, filerPort, func(client filer_pb.SeaweedFilerClient) error {
+
+ request := &filer_pb.LookupDirectoryEntryRequest{
+ Name: name,
+ Directory: dir,
+ }
+ respLookupEntry, err := client.LookupDirectoryEntry(ctx, request)
+ if err != nil {
+ return err
+ }
+
+ m := jsonpb.Marshaler{
+ EmitDefaults: true,
+ Indent: " ",
+ }
+
+ text, marshalErr := m.MarshalToString(respLookupEntry.Entry)
+ if marshalErr != nil {
+ return fmt.Errorf("marshal meta: %v", marshalErr)
+ }
+
+ fmt.Fprintf(writer, "%s\n", text)
+
+ return nil
+
+ })
+
+}