dirInfo checks whether maybeDir is a directory schema, and if so returns the corresponding fileInfo. If dir is another kind of (valid) file schema, errNotDir is returned.
(ctx context.Context, dir blob.Ref)
| 98 | // corresponding fileInfo. If dir is another kind of (valid) file schema, errNotDir |
| 99 | // is returned. |
| 100 | func (dh *DownloadHandler) dirInfo(ctx context.Context, dir blob.Ref) (fi fileInfo, err error) { |
| 101 | rc, _, err := dh.Fetcher.Fetch(ctx, dir) |
| 102 | if err != nil { |
| 103 | return fi, fmt.Errorf("could not fetch %v: %v", dir, err) |
| 104 | } |
| 105 | b, err := schema.BlobFromReader(dir, rc) |
| 106 | rc.Close() |
| 107 | if err != nil { |
| 108 | return fi, fmt.Errorf("could not read %v as blob: %v", dir, err) |
| 109 | } |
| 110 | tp := b.Type() |
| 111 | if tp != "directory" { |
| 112 | return fi, errNotDir |
| 113 | } |
| 114 | dr, err := schema.NewDirReader(ctx, dh.Fetcher, dir) |
| 115 | if err != nil { |
| 116 | return fi, fmt.Errorf("could not open %v as directory: %v", dir, err) |
| 117 | } |
| 118 | children, err := dr.StaticSet(ctx) |
| 119 | if err != nil { |
| 120 | return fi, fmt.Errorf("could not get dir entries of %v: %v", dir, err) |
| 121 | } |
| 122 | return fileInfo{ |
| 123 | isDir: true, |
| 124 | name: b.FileName(), |
| 125 | modtime: b.ModTime(), |
| 126 | children: children, |
| 127 | }, nil |
| 128 | } |
| 129 | |
| 130 | func (dh *DownloadHandler) fileInfo(ctx context.Context, file blob.Ref) (fi fileInfo, packed bool, err error) { |
| 131 | // Need to get the type first, because we can't use NewFileReader on a non-regular file. |
no test coverage detected