@cryptotaxi247 / kubo / commits / 1fef9a51d

coreapi ls: merge ResolveType and ResolveSize

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Feb 2, 2019 at 17:13 UTC 1fef9a51dda4c399bd621adda94b031a6e9e5d41
3 files changed +8 -22
core/commands/ls.go
+1 -2
@@ -136,8 +136,7 @@ The JSON output contains type information.
136 }
137
138 results, err := api.Unixfs().Ls(req.Context, p,
139 - options.Unixfs.ResolveType(resolveType),
140 - options.Unixfs.ResolveSize(resolveSize))
139 + options.Unixfs.ResolveChildren(resolveSize || resolveType))
140 if err != nil {
141 return err
142 }
core/coreapi/interface/options/unixfs.go
+4 -13
@@ -43,8 +43,7 @@ type UnixfsAddSettings struct {
43 }
44
45 type UnixfsLsSettings struct {
46 - ResolveType bool
47 - ResolveSize bool
46 + ResolveChildren bool
47 }
48
49 type UnixfsAddOption func(*UnixfsAddSettings) error
@@ -130,8 +129,7 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
129
130 func UnixfsLsOptions(opts ...UnixfsLsOption) (*UnixfsLsSettings, error) {
131 options := &UnixfsLsSettings{
133 - ResolveSize: true,
134 - ResolveType: true,
132 + ResolveChildren: true,
133 }
134
135 for _, opt := range opts {
@@ -313,16 +311,9 @@ func (unixfsOpts) Nocopy(enable bool) UnixfsAddOption {
311 }
312 }
313
316 -func (unixfsOpts) ResolveSize(resolve bool) UnixfsLsOption {
314 +func (unixfsOpts) ResolveChildren(resolve bool) UnixfsLsOption {
315 return func(settings *UnixfsLsSettings) error {
318 - settings.ResolveSize = resolve
319 - return nil
320 - }
321 -}
322 -
323 -func (unixfsOpts) ResolveType(resolve bool) UnixfsLsOption {
324 - return func(settings *UnixfsLsSettings) error {
325 - settings.ResolveType = resolve
316 + settings.ResolveChildren = resolve
317 return nil
318 }
319 }
core/coreapi/unixfs.go
+3 -7
@@ -185,7 +185,7 @@ func (api *UnixfsAPI) processLink(ctx context.Context, linkres ft.LinkResult, se
185 lnk.Type = ft.TFile
186 lnk.Size = lnk.Link.Size
187 case cid.DagProtobuf:
188 - if !settings.ResolveSize && !settings.ResolveType {
188 + if !settings.ResolveChildren {
189 break
190 }
191
@@ -201,12 +201,8 @@ func (api *UnixfsAPI) processLink(ctx context.Context, linkres ft.LinkResult, se
201 lnk.Err = err
202 break
203 }
204 - if settings.ResolveType {
205 - lnk.Type = d.Type()
206 - }
207 - if d.Type() == ft.TFile && settings.ResolveSize {
208 - lnk.Size = d.FileSize()
209 - }
204 + lnk.Type = d.Type()
205 + lnk.Size = d.FileSize()
206 }
207 }
208