Mount to the provided target.
(target string)
| 36 | |
| 37 | // Mount to the provided target. |
| 38 | func (m *Mount) mount(target string) (retErr error) { |
| 39 | if m.Type != "windows-layer" { |
| 40 | return fmt.Errorf("invalid windows mount type: '%s'", m.Type) |
| 41 | } |
| 42 | |
| 43 | home, layerID := filepath.Split(m.Source) |
| 44 | |
| 45 | parentLayerPaths, err := m.GetParentPaths() |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | |
| 50 | var di = hcsshim.DriverInfo{ |
| 51 | HomeDir: home, |
| 52 | } |
| 53 | |
| 54 | if err := hcsshim.ActivateLayer(di, layerID); err != nil { |
| 55 | return fmt.Errorf("failed to activate layer %s: %w", m.Source, err) |
| 56 | } |
| 57 | defer func() { |
| 58 | if retErr != nil { |
| 59 | if layerErr := hcsshim.DeactivateLayer(di, layerID); layerErr != nil { |
| 60 | log.G(context.TODO()).WithError(layerErr).Error("failed to deactivate layer during mount failure cleanup") |
| 61 | } |
| 62 | } |
| 63 | }() |
| 64 | |
| 65 | if err := hcsshim.PrepareLayer(di, layerID, parentLayerPaths); err != nil { |
| 66 | return fmt.Errorf("failed to prepare layer %s: %w", m.Source, err) |
| 67 | } |
| 68 | |
| 69 | defer func() { |
| 70 | if retErr != nil { |
| 71 | if layerErr := hcsshim.UnprepareLayer(di, layerID); layerErr != nil { |
| 72 | log.G(context.TODO()).WithError(layerErr).Error("failed to unprepare layer during mount failure cleanup") |
| 73 | } |
| 74 | } |
| 75 | }() |
| 76 | |
| 77 | volume, err := hcsshim.GetLayerMountPath(di, layerID) |
| 78 | if err != nil { |
| 79 | return fmt.Errorf("failed to get volume path for layer %s: %w", m.Source, err) |
| 80 | } |
| 81 | |
| 82 | if len(parentLayerPaths) == 0 { |
| 83 | // this is a base layer. It gets mounted without going through WCIFS. We need to mount the Files |
| 84 | // folder, not the actual source, or the client may inadvertently remove metadata files. |
| 85 | volume = filepath.Join(volume, "Files") |
| 86 | if _, err := os.Stat(volume); err != nil { |
| 87 | return fmt.Errorf("no Files folder in layer %s", layerID) |
| 88 | } |
| 89 | } |
| 90 | if err := bindfilter.ApplyFileBinding(target, volume, m.ReadOnly()); err != nil { |
| 91 | return fmt.Errorf("failed to set volume mount path for layer %s: %w", m.Source, err) |
| 92 | } |
| 93 | defer func() { |
| 94 | if retErr != nil { |
| 95 | if bindErr := bindfilter.RemoveFileBinding(target); bindErr != nil { |
nothing calls this directly
no test coverage detected