(store database.Store, fileID uuid.UUID)
| 288 | } |
| 289 | |
| 290 | func 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 | } |
no test coverage detected