-
Notifications
You must be signed in to change notification settings - Fork 4
/
dotnet_root_manager.go
55 lines (44 loc) · 1.42 KB
/
dotnet_root_manager.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dotnetpublish
import (
"fmt"
"os"
"path/filepath"
"github.com/paketo-buildpacks/packit/fs"
)
type DotnetRootManager struct{}
func NewDotnetRootManager() DotnetRootManager {
return DotnetRootManager{}
}
func (m DotnetRootManager) Setup(root, existingRoot, sdkLocation string) error {
paths, err := filepath.Glob(filepath.Join(existingRoot, "shared", "*"))
if err != nil {
return fmt.Errorf("could not glob %s: %w", filepath.Join(existingRoot, "shared", "*"), err)
}
paths = append(paths, filepath.Join(existingRoot, "host"))
for _, path := range paths {
relPath, err := filepath.Rel(existingRoot, path)
if err != nil {
return err
}
newPath := filepath.Join(root, relPath)
err = os.MkdirAll(filepath.Dir(newPath), os.ModePerm)
if err != nil {
return fmt.Errorf("could not write to %s: %w", filepath.Dir(newPath), err)
}
err = os.Symlink(path, newPath)
if err != nil {
return fmt.Errorf("could not create symlink: %w", err)
}
}
// NOTE: the dotnet CLI uses relative pathing that means we must copy it into
// the final DOTNET_ROOT so that it can find SDKs.
err = fs.Copy(filepath.Join(existingRoot, "dotnet"), filepath.Join(root, "dotnet"))
if err != nil {
return fmt.Errorf("could not copy the dotnet cli: %w", err)
}
err = os.Symlink(filepath.Join(sdkLocation, "sdk"), filepath.Join(root, "sdk"))
if err != nil {
return fmt.Errorf("could not create symlink: %w", err)
}
return nil
}