MCPcopy
hub / github.com/kopia/kopia / printDirectoryEntry

Method printDirectoryEntry

cli/command_ls.go:91–142  ·  view source on GitHub ↗
(ctx context.Context, e fs.Entry, prefix, indent string)

Source from the content-addressed store, hash-verified

89}
90
91func (c *commandList) printDirectoryEntry(ctx context.Context, e fs.Entry, prefix, indent string) error {
92 hoid, ok := e.(object.HasObjectID)
93 if !ok {
94 return errors.New("entry without object ID")
95 }
96
97 objectID := hoid.ObjectID()
98 oid := objectID.String()
99 col := defaultColor
100
101 var (
102 errorSummary string
103 info string
104 )
105
106 if dws, ok := e.(fs.DirectoryWithSummary); ok && c.errorSummary {
107 if ds, _ := dws.Summary(ctx); ds != nil && ds.FatalErrorCount > 0 {
108 errorSummary = fmt.Sprintf(" (%v errors)", ds.FatalErrorCount)
109 col = errorColor
110 }
111 }
112
113 switch {
114 case c.long:
115 info = fmt.Sprintf(
116 "%v %12s %v %-34v %v%v",
117 e.Mode(),
118 maybeHumanReadableBytes(c.humanReadable, e.Size()),
119 formatTimestamp(e.ModTime().Local()),
120 oid,
121 c.nameToDisplay(prefix, e),
122 errorSummary,
123 )
124 case c.showOID:
125 info = fmt.Sprintf("%-34v %v%v", oid, c.nameToDisplay(prefix, e), errorSummary)
126
127 default:
128 info = fmt.Sprintf("%v%v", c.nameToDisplay(prefix, e), errorSummary)
129 }
130
131 col.Fprintln(c.out.stdout(), info) //nolint:errcheck
132
133 if c.recursive {
134 if subdir, ok := e.(fs.Directory); ok {
135 if listerr := c.listDirectory(ctx, subdir, prefix+e.Name()+"/", indent+" "); listerr != nil {
136 return listerr
137 }
138 }
139 }
140
141 return nil
142}
143
144func (c *commandList) nameToDisplay(prefix string, e fs.Entry) string {
145 suffix := ""

Callers 1

listDirectoryMethod · 0.95

Calls 12

nameToDisplayMethod · 0.95
listDirectoryMethod · 0.95
maybeHumanReadableBytesFunction · 0.85
formatTimestampFunction · 0.85
ObjectIDMethod · 0.65
SummaryMethod · 0.65
stdoutMethod · 0.65
NameMethod · 0.65
StringMethod · 0.45
ModeMethod · 0.45
SizeMethod · 0.45
ModTimeMethod · 0.45

Tested by

no test coverage detected