MCPcopy
hub / github.com/perkeep/perkeep / dirInfo

Method dirInfo

pkg/server/download.go:100–128  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

98// corresponding fileInfo. If dir is another kind of (valid) file schema, errNotDir
99// is returned.
100func (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
130func (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.

Callers 1

zipFileMethod · 0.95

Calls 8

StaticSetMethod · 0.95
BlobFromReaderFunction · 0.92
NewDirReaderFunction · 0.92
FetchMethod · 0.65
CloseMethod · 0.65
FileNameMethod · 0.65
TypeMethod · 0.45
ModTimeMethod · 0.45

Tested by

no test coverage detected