MCPcopy
hub / github.com/rclone/rclone / newListJSON

Function newListJSON

fs/operations/lsjson.go:104–154  ·  view source on GitHub ↗
(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt)

Source from the content-addressed store, hash-verified

102}
103
104func newListJSON(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt) (*listJSON, error) {
105 lj := &listJSON{
106 fsrc: fsrc,
107 remote: remote,
108 opt: opt,
109 dirs: true,
110 files: true,
111 }
112 // Dirs Files
113 // !FilesOnly,!DirsOnly true true
114 // !FilesOnly,DirsOnly true false
115 // FilesOnly,!DirsOnly false true
116 // FilesOnly,DirsOnly true true
117 if !opt.FilesOnly && opt.DirsOnly {
118 lj.files = false
119 } else if opt.FilesOnly && !opt.DirsOnly {
120 lj.dirs = false
121 }
122 if opt.ShowEncrypted {
123 fsInfo, _, _, config, err := fs.ConfigFs(fs.ConfigStringFull(fsrc))
124 if err != nil {
125 return nil, fmt.Errorf("ListJSON failed to load config for crypt remote: %w", err)
126 }
127 if fsInfo.Name != "crypt" {
128 return nil, errors.New("the remote needs to be of type \"crypt\"")
129 }
130 lj.cipher, err = crypt.NewCipher(config)
131 if err != nil {
132 return nil, fmt.Errorf("ListJSON failed to make new crypt remote: %w", err)
133 }
134 }
135 features := fsrc.Features()
136 lj.canGetTier = features.GetTier
137 lj.format = formatForPrecision(fsrc.Precision())
138 lj.isBucket = features.BucketBased && remote == "" && fsrc.Root() == "" // if bucket-based remote listing the root mark directories as buckets
139 lj.showHash = opt.ShowHash
140 lj.hashTypes = fsrc.Hashes().Array()
141 if len(opt.HashTypes) != 0 {
142 lj.showHash = true
143 lj.hashTypes = []hash.Type{}
144 for _, hashType := range opt.HashTypes {
145 var ht hash.Type
146 err := ht.Set(hashType)
147 if err != nil {
148 return nil, err
149 }
150 lj.hashTypes = append(lj.hashTypes, ht)
151 }
152 }
153 return lj, nil
154}
155
156// Convert a single entry to JSON
157//

Callers 3

NewListJSONMethod · 0.85
ListJSONFunction · 0.85
StatJSONFunction · 0.85

Calls 11

SetMethod · 0.95
ConfigFsFunction · 0.92
ConfigStringFullFunction · 0.92
NewCipherFunction · 0.92
formatForPrecisionFunction · 0.85
ArrayMethod · 0.80
FeaturesMethod · 0.65
PrecisionMethod · 0.65
RootMethod · 0.65
HashesMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…