forked from cloudfoundry-attic/bosh-init
-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp_root_configurator.go
38 lines (30 loc) · 971 Bytes
/
temp_root_configurator.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
package cmd
import (
"github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system"
)
type TempRootConfigurator interface {
PrepareAndSetTempRoot(path string, logger logger.Logger) error
}
type tempRootConfigurator struct {
fs boshsys.FileSystem
}
func NewTempRootConfigurator(fs boshsys.FileSystem) TempRootConfigurator {
return &tempRootConfigurator{fs: fs}
}
func (c *tempRootConfigurator) PrepareAndSetTempRoot(path string, logger logger.Logger) error {
logger.Info("tempRootConfigurator", "Preparing temp root: %s", path)
if c.fs.FileExists(path) {
logger.Info("tempRootConfigurator", "Path exists, deleting")
err := c.fs.RemoveAll(path)
if err != nil {
return err
}
}
logger.Info("tempRootConfigurator", "Setting file system temp root")
err := c.fs.ChangeTempRoot(path)
if err != nil {
return err
}
return nil
}