forked from concourse/baggageclaim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace.go
44 lines (32 loc) · 955 Bytes
/
namespace.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
package uidgid
import (
"os/exec"
"path/filepath"
"code.cloudfoundry.org/lager"
)
//go:generate counterfeiter . Namespacer
type Namespacer interface {
NamespacePath(logger lager.Logger, path string) error
NamespaceCommand(cmd *exec.Cmd)
}
type UidNamespacer struct {
Translator Translator
Logger lager.Logger
}
func (n *UidNamespacer) NamespacePath(logger lager.Logger, rootfsPath string) error {
log := logger.Session("namespace", lager.Data{
"path": rootfsPath,
})
log.Debug("start")
defer log.Debug("done")
if err := filepath.Walk(rootfsPath, n.Translator.TranslatePath); err != nil {
log.Error("failed-to-walk-and-translate", err)
}
return nil
}
func (n *UidNamespacer) NamespaceCommand(cmd *exec.Cmd) {
n.Translator.TranslateCommand(cmd)
}
type NoopNamespacer struct{}
func (NoopNamespacer) NamespacePath(lager.Logger, string) error { return nil }
func (NoopNamespacer) NamespaceCommand(cmd *exec.Cmd) {}