MCPcopy
hub / github.com/rclone/rclone / entry

Method entry

fs/operations/lsjson.go:159–240  ·  view source on GitHub ↗

Convert a single entry to JSON It may return nil if there is no entry to return

(ctx context.Context, entry fs.DirEntry)

Source from the content-addressed store, hash-verified

157//
158// It may return nil if there is no entry to return
159func (lj *listJSON) entry(ctx context.Context, entry fs.DirEntry) (*ListJSONItem, error) {
160 switch entry.(type) {
161 case fs.Directory:
162 if lj.opt.FilesOnly {
163 return nil, nil
164 }
165 case fs.Object:
166 if lj.opt.DirsOnly {
167 return nil, nil
168 }
169 default:
170 fs.Errorf(nil, "Unknown type %T in listing", entry)
171 }
172
173 item := &ListJSONItem{
174 Path: entry.Remote(),
175 Name: path.Base(entry.Remote()),
176 Size: entry.Size(),
177 }
178 if entry.Remote() == "" {
179 item.Name = ""
180 }
181 if !lj.opt.NoModTime {
182 item.ModTime = Timestamp{When: entry.ModTime(ctx), Format: lj.format}
183 }
184 if !lj.opt.NoMimeType {
185 item.MimeType = fs.MimeTypeDirEntry(ctx, entry)
186 }
187 if lj.cipher != nil {
188 switch entry.(type) {
189 case fs.Directory:
190 item.EncryptedPath = lj.cipher.EncryptDirName(entry.Remote())
191 case fs.Object:
192 item.EncryptedPath = lj.cipher.EncryptFileName(entry.Remote())
193 default:
194 fs.Errorf(nil, "Unknown type %T in listing", entry)
195 }
196 item.Encrypted = path.Base(item.EncryptedPath)
197 }
198 if lj.opt.Metadata {
199 metadata, err := fs.GetMetadata(ctx, entry)
200 if err != nil {
201 fs.Errorf(entry, "Failed to read metadata: %v", err)
202 } else if metadata != nil {
203 item.Metadata = metadata
204 }
205 }
206 if do, ok := entry.(fs.IDer); ok {
207 item.ID = do.ID()
208 }
209 if o, ok := entry.(fs.Object); lj.opt.ShowOrigIDs && ok {
210 if do, ok := fs.UnWrapObject(o).(fs.IDer); ok {
211 item.OrigID = do.ID()
212 }
213 }
214 switch x := entry.(type) {
215 case fs.Directory:
216 item.IsDir = true

Callers 3

JSONEntryMethod · 0.80
ListJSONFunction · 0.80
StatJSONFunction · 0.80

Calls 14

ErrorfFunction · 0.92
MimeTypeDirEntryFunction · 0.92
GetMetadataFunction · 0.92
UnWrapObjectFunction · 0.92
BaseMethod · 0.80
EncryptDirNameMethod · 0.80
RemoteMethod · 0.65
SizeMethod · 0.65
ModTimeMethod · 0.65
IDMethod · 0.65
HashMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected