...

Source file src/github.com/Microsoft/hcsshim/internal/wcow/scratch.go

Documentation: github.com/Microsoft/hcsshim/internal/wcow

     1  //go:build windows
     2  
     3  package wcow
     4  
     5  import (
     6  	"context"
     7  	"os"
     8  	"path/filepath"
     9  
    10  	"github.com/Microsoft/hcsshim/internal/copyfile"
    11  	"github.com/Microsoft/hcsshim/internal/wclayer"
    12  )
    13  
    14  // CreateUVMScratch is a helper to create a scratch for a Windows utility VM
    15  // with permissions to the specified VM ID in a specified directory
    16  func CreateUVMScratch(ctx context.Context, imagePath, destDirectory, vmID string) error {
    17  	sourceScratch := filepath.Join(imagePath, `UtilityVM\SystemTemplate.vhdx`)
    18  	targetScratch := filepath.Join(destDirectory, "sandbox.vhdx")
    19  	if err := copyfile.CopyFile(ctx, sourceScratch, targetScratch, true); err != nil {
    20  		return err
    21  	}
    22  	if err := wclayer.GrantVmAccess(ctx, vmID, targetScratch); err != nil {
    23  		os.Remove(targetScratch)
    24  		return err
    25  	}
    26  	return nil
    27  }
    28  

View as plain text