MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / HeadObject

Method HeadObject

server/s3/backend.go:104–144  ·  view source on GitHub ↗

HeadObject returns the fileinfo for the given object name. Note that the metadata is not supported yet.

(ctx context.Context, bucketName, objectName string)

Source from the content-addressed store, hash-verified

102//
103// Note that the metadata is not supported yet.
104func (b *s3Backend) HeadObject(ctx context.Context, bucketName, objectName string) (*gofakes3.Object, error) {
105 bucket, err := getBucketByName(bucketName)
106 if err != nil {
107 return nil, err
108 }
109 bucketPath := bucket.Path
110
111 fp := path.Join(bucketPath, objectName)
112 fmeta, _ := op.GetNearestMeta(fp)
113 node, err := fs.Get(context.WithValue(ctx, conf.MetaKey, fmeta), fp, &fs.GetArgs{})
114 if err != nil {
115 return nil, gofakes3.KeyNotFound(objectName)
116 }
117
118 if node.IsDir() {
119 return nil, gofakes3.KeyNotFound(objectName)
120 }
121
122 size := node.GetSize()
123 // hash := getFileHashByte(fobj)
124
125 meta := map[string]string{
126 "Last-Modified": node.ModTime().Format(timeFormat),
127 "Content-Type": utils.GetMimeType(fp),
128 }
129
130 if val, ok := b.meta.Load(fp); ok {
131 metaMap := val.(map[string]string)
132 for k, v := range metaMap {
133 meta[k] = v
134 }
135 }
136
137 return &gofakes3.Object{
138 Name: objectName,
139 // Hash: hash,
140 Metadata: meta,
141 Size: size,
142 Contents: noOpReadCloser{},
143 }, nil
144}
145
146// GetObject fetchs the object from the filesystem.
147func (b *s3Backend) GetObject(ctx context.Context, bucketName, objectName string, rangeRequest *gofakes3.ObjectRangeRequest) (s3Obj *gofakes3.Object, err error) {

Callers

nothing calls this directly

Calls 8

GetNearestMetaFunction · 0.92
GetFunction · 0.92
GetMimeTypeFunction · 0.92
getBucketByNameFunction · 0.85
IsDirMethod · 0.65
GetSizeMethod · 0.65
ModTimeMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected