-
Notifications
You must be signed in to change notification settings - Fork 36
/
os_file_system_unix.go
54 lines (43 loc) · 1.23 KB
/
os_file_system_unix.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
//+build !windows
package system
import (
"errors"
"fmt"
"strings"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
)
func (fs *osFileSystem) homeDir(username string) (string, error) {
homeDir, err := fs.runCommand(fmt.Sprintf("echo ~%s", username))
if err != nil {
return "", bosherr.WrapErrorf(err, "Shelling out to get user '%s' home directory", username)
}
if strings.HasPrefix(homeDir, "~") {
return "", bosherr.Errorf("Failed to get user '%s' home directory", username)
}
return homeDir, nil
}
func (fs *osFileSystem) chown(path, owner string) error {
if owner == "" {
return errors.New("Failed to lookup user ''")
}
var group string
var err error
ownerSplit := strings.Split(owner, ":")
user := ownerSplit[0]
if len(ownerSplit) <= 1 {
group, err = fs.runCommand(fmt.Sprintf("id -g %s", user))
if err != nil {
return bosherr.WrapErrorf(err, "Failed to lookup user '%s'", user)
}
} else {
group = ownerSplit[1]
}
_, err = fs.runCommand(fmt.Sprintf("chown '%s:%s' '%s'", user, group, path))
if err != nil {
return bosherr.WrapError(err, "Failed to chown")
}
return nil
}
func (fs *osFileSystem) symlinkPaths(oldPath, newPath string) (old, new string, err error) {
return oldPath, newPath, nil
}