...
1 package uvmfolder
2
3 import (
4 "context"
5 "fmt"
6 "os"
7 "path/filepath"
8
9 "github.com/Microsoft/hcsshim/internal/log"
10 "github.com/sirupsen/logrus"
11 )
12
13
14
15
16
17
18 func LocateUVMFolder(ctx context.Context, layerFolders []string) (string, error) {
19 var uvmFolder string
20 index := 0
21 for _, layerFolder := range layerFolders {
22 _, err := os.Stat(filepath.Join(layerFolder, `UtilityVM`))
23 if err == nil {
24 uvmFolder = layerFolder
25 break
26 }
27 if !os.IsNotExist(err) {
28 return "", err
29 }
30 index++
31 }
32 if uvmFolder == "" {
33 return "", fmt.Errorf("utility VM folder could not be found in layers")
34 }
35 log.G(ctx).WithFields(logrus.Fields{
36 "index": index + 1,
37 "count": len(layerFolders),
38 "folder": uvmFolder,
39 }).Debug("hcsshim::LocateUVMFolder: found")
40 return uvmFolder, nil
41 }
42
View as plain text