(ctx context.Context, fsrc fs.Fs, remote string, opt *ListJSONOpt)
| 102 | } |
| 103 | |
| 104 | func 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 | // |
no test coverage detected
searching dependent graphs…