( ctx context.Context, query *Query, name string, permissions int, )
| 375 | } |
| 376 | |
| 377 | func (state *HTTPState) fileResult( |
| 378 | ctx context.Context, |
| 379 | query *Query, |
| 380 | name string, |
| 381 | permissions int, |
| 382 | ) (*HTTPFetchResult, error) { |
| 383 | if state.snapshot == nil { |
| 384 | return nil, fmt.Errorf("http state %q has no snapshot", state.URL) |
| 385 | } |
| 386 | newRef, err := query.SnapshotManager().New( |
| 387 | ctx, |
| 388 | state.snapshot, |
| 389 | bkcache.WithRecordType(bkclient.UsageRecordTypeRegular), |
| 390 | bkcache.WithDescription(fmt.Sprintf("http state resolve %s", name)), |
| 391 | ) |
| 392 | if err != nil { |
| 393 | return nil, err |
| 394 | } |
| 395 | err = MountRef(ctx, newRef, func(root string, _ *mount.Mount) error { |
| 396 | src, err := RootPathWithoutFinalSymlink(root, httpStateCanonicalPath) |
| 397 | if err != nil { |
| 398 | return err |
| 399 | } |
| 400 | dst, err := RootPathWithoutFinalSymlink(root, name) |
| 401 | if err != nil { |
| 402 | return err |
| 403 | } |
| 404 | if err := os.Rename(src, dst); err != nil { |
| 405 | return TrimErrPathPrefix(err, root) |
| 406 | } |
| 407 | if err := os.Chmod(dst, os.FileMode(permissions)); err != nil { |
| 408 | return TrimErrPathPrefix(err, root) |
| 409 | } |
| 410 | return nil |
| 411 | }) |
| 412 | if err != nil { |
| 413 | _ = newRef.Release(context.WithoutCancel(ctx)) |
| 414 | return nil, err |
| 415 | } |
| 416 | snap, err := newRef.Commit(ctx) |
| 417 | if err != nil { |
| 418 | return nil, err |
| 419 | } |
| 420 | file := &File{ |
| 421 | Platform: query.Platform(), |
| 422 | File: new(LazyAccessor[string, *File]), |
| 423 | Snapshot: new(LazyAccessor[bkcache.ImmutableRef, *File]), |
| 424 | } |
| 425 | file.File.setValue(name) |
| 426 | file.Snapshot.setValue(snap) |
| 427 | return &HTTPFetchResult{ |
| 428 | File: file, |
| 429 | ContentDigest: state.ContentDigest, |
| 430 | LastModified: state.LastModified, |
| 431 | }, nil |
| 432 | } |
| 433 | |
| 434 | func FetchHTTPFile( |
no test coverage detected