Skip to content

Commit 5ebc1c5

Browse files
authored
Store extraction error for LazyImageLayers (#2429)
* Store extraction error for `LazyImageLayers` Have `test\internal\layers.LazyImageLayers` always fail if image extraction fails initially. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com> * Build required binaries Add build stages for various binaries to ensure they compile without issue. Alphabetize build steps to make lookup easier. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com> --------- Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
1 parent 75059e3 commit 5ebc1c5

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,20 +632,30 @@ jobs:
632632
633633
- run: ${{ env.GO_BUILD_CMD }} ./cmd/containerd-shim-runhcs-v1
634634
name: Build containerd-shim-runhcs-v1.exe
635+
- run: ${{ env.GO_BUILD_CMD }} ./cmd/device-util
636+
name: Build device-util.exe
637+
- run: ${{ env.GO_BUILD_CMD }} ./cmd/jobobject-util
638+
name: Build jobobject-util.exe
639+
- run: ${{ env.GO_BUILD_CMD }} ./cmd/mkuvmcim
640+
name: Build mkuvmcim.exe
641+
- run: ${{ env.GO_BUILD_CMD }} ./cmd/ncproxy
642+
name: Build ncproxy.exe
635643
- run: ${{ env.GO_BUILD_CMD }} ./cmd/runhcs
636644
name: Build runhcs.exe
645+
- run: ${{ env.GO_BUILD_CMD }} ./cmd/shimdiag
646+
name: Build shimdiag.exe
637647
- run: ${{ env.GO_BUILD_CMD }} ./cmd/tar2ext4
638648
name: Build tar2ext4.exe
639649
- run: ${{ env.GO_BUILD_CMD }} ./cmd/wclayer
640650
name: Build wclayer.exe
641-
- run: ${{ env.GO_BUILD_CMD }} ./cmd/device-util
642-
name: Build device-util.exe
643-
- run: ${{ env.GO_BUILD_CMD }} ./cmd/ncproxy
644-
name: Build ncproxy.exe
645651
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/grantvmgroupaccess
646652
name: Build grantvmgroupaccess.exe
653+
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/hvsocketaddr
654+
name: Build hvsocketaddr.exe
647655
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/networkagent
648656
name: Build networkagent.exe
657+
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/rootfs
658+
name: Build rootfs.exe
649659
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/securitypolicy
650660
name: Build securitypolicy.exe
651661
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/securitypolicy
@@ -657,8 +667,6 @@ jobs:
657667
name: Build uvmboot.exe
658668
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/zapdir
659669
name: Build zapdir.exe
660-
- run: ${{ env.GO_BUILD_CMD }} ./internal/tools/hvsocketaddr
661-
name: Build hvsocketaddr.exe
662670

663671
- uses: actions/upload-artifact@v4
664672
if: ${{ github.event_name == 'pull_request' }}

internal/safefile/safeopen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
winio "github.com/Microsoft/go-winio"
1919
)
2020

21+
// TODO(go1.24): use [os.Root] and co. here
22+
2123
func OpenRoot(path string) (*os.File, error) {
2224
longpath, err := longpath.LongAbs(path)
2325
if err != nil {

test/internal/layers/lazy.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ type LazyImageLayers struct {
4242
// Defaults to [os.TempDir] if left empty.
4343
TempPath string
4444
// dedicated directory, under [TempPath], to store layers in
45-
dir string
46-
once sync.Once
47-
layers []string // extracted layer directories, under [dir]
45+
dir string
46+
47+
once sync.Once // sets the [layers] and [extractErr] fields
48+
layers []string // extracted layer directories, under [dir]
49+
extractErr error // extraction error
4850
}
4951

5052
type extractHandler func(ctx context.Context, rc io.ReadCloser, dir string, parents []string) error
@@ -62,7 +64,10 @@ func (x *LazyImageLayers) Close(ctx context.Context) error {
6264
"image": x.Image,
6365
}).Debug("removing image")
6466

65-
if _, err := os.Stat(x.dir); err != nil && !os.IsNotExist(err) {
67+
if _, err := os.Stat(x.dir); err != nil {
68+
if os.IsNotExist(err) {
69+
return nil
70+
}
6671
return fmt.Errorf("path %q is not valid: %w", x.dir, err)
6772
}
6873

@@ -83,13 +88,12 @@ func (x *LazyImageLayers) Layers(ctx context.Context, tb testing.TB) []string {
8388
return nil
8489
}
8590

86-
var err error
8791
x.once.Do(func() {
88-
err = x.extractLayers(ctx)
92+
x.extractErr = x.extractLayers(ctx)
8993
})
90-
if err != nil {
94+
if x.extractErr != nil {
9195
x.Close(ctx)
92-
tb.Fatal(err)
96+
tb.Fatal(x.extractErr)
9397
}
9498
return x.layers
9599
}

0 commit comments

Comments
 (0)