forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat.go
75 lines (61 loc) · 1.61 KB
/
stat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package main
import (
"flag"
"fmt"
"time"
"github.com/keybase/kbfs/fsrpc"
"github.com/keybase/kbfs/libkbfs"
"golang.org/x/net/context"
)
func statNode(ctx context.Context, config libkbfs.Config, nodePathStr string) error {
p, err := fsrpc.NewPath(nodePathStr)
if err != nil {
return err
}
n, ei, err := p.GetNode(ctx, config)
if err != nil {
return err
}
// If n is non-nil, ignore the EntryInfo returned by
// p.getNode() so we can exercise the Stat() codepath. We
// can't compare the two, since they might legitimately differ
// due to races.
if n != nil {
ei, err = config.KBFSOps().Stat(ctx, n)
if err != nil {
return err
}
}
var symPathStr string
if ei.Type == libkbfs.Sym {
symPathStr = fmt.Sprintf("SymPath: %s, ", ei.SymPath)
}
mtimeStr := time.Unix(0, ei.Mtime).String()
ctimeStr := time.Unix(0, ei.Ctime).String()
fmt.Printf("{Type: %s, Size: %d, %sMtime: %s, Ctime: %s}\n", ei.Type, ei.Size, symPathStr, mtimeStr, ctimeStr)
return nil
}
func stat(ctx context.Context, config libkbfs.Config, args []string) (exitStatus int) {
flags := flag.NewFlagSet("kbfs stat", flag.ContinueOnError)
err := flags.Parse(args)
if err != nil {
printError("stat", err)
return 1
}
nodePaths := flags.Args()
if len(nodePaths) == 0 {
printError("stat", errAtLeastOnePath)
return 1
}
for _, nodePath := range nodePaths {
err := statNode(ctx, config, nodePath)
if err != nil {
printError("stat", err)
return 1
}
}
return 0
}