MCPcopy Index your code
hub / github.com/coder/coder / fetch

Function fetch

coderd/files/cache.go:290–323  ·  view source on GitHub ↗
(store database.Store, fileID uuid.UUID)

Source from the content-addressed store, hash-verified

288}
289
290func fetch(store database.Store, fileID uuid.UUID) (CacheEntryValue, error) {
291 // Because many callers can be waiting on the same file fetch concurrently, we
292 // want to prevent any failures that would cause them all to receive errors
293 // because the caller who initiated the fetch would fail.
294 // - We always run the fetch with an uncancelable context, and then check
295 // context cancellation for each acquirer afterwards.
296 // - We always run the fetch as a system user, and then check authorization
297 // for each acquirer afterwards.
298 // This prevents a canceled context or an unauthorized user from "holding up
299 // the queue".
300 //nolint:gocritic
301 file, err := store.GetFileByID(dbauthz.AsFileReader(context.Background()), fileID)
302 if err != nil {
303 return CacheEntryValue{}, xerrors.Errorf("failed to read file from database: %w", err)
304 }
305
306 var files fs.FS
307 switch file.Mimetype {
308 case "application/zip", "application/x-zip-compressed":
309 files, err = archivefs.FromZipReader(bytes.NewReader(file.Data), int64(len(file.Data)))
310 if err != nil {
311 return CacheEntryValue{}, xerrors.Errorf("failed to read zip file: %w", err)
312 }
313 default:
314 // Assume '"application/x-tar"' as the default mimetype.
315 files = archivefs.FromTarReader(bytes.NewBuffer(file.Data))
316 }
317
318 return CacheEntryValue{
319 Object: file.RBACObject(),
320 FS: files,
321 Size: int64(len(file.Data)),
322 }, nil
323}

Callers 6

prepareMethod · 0.70
UsersPaginationFunction · 0.50
UsersFilterFunction · 0.50
UpdateMethod · 0.50
AgentFunction · 0.50

Calls 4

AsFileReaderFunction · 0.92
GetFileByIDMethod · 0.65
RBACObjectMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected