1//+build !windows 2 3package system 4 5import ( 6 "fmt" 7 "strings" 8 9 "errors" 10 bosherr "github.com/cloudfoundry/bosh-utils/errors" 11) 12 13func (fs *osFileSystem) homeDir(username string) (string, error) { 14 homeDir, err := fs.runCommand(fmt.Sprintf("echo ~%s", username)) 15 if err != nil { 16 return "", bosherr.WrapErrorf(err, "Shelling out to get user '%s' home directory", username) 17 } 18 if strings.HasPrefix(homeDir, "~") { 19 return "", bosherr.Errorf("Failed to get user '%s' home directory", username) 20 } 21 return homeDir, nil 22} 23 24func (fs *osFileSystem) currentHomeDir() (string, error) { 25 return fs.HomeDir("") 26} 27 28func (fs *osFileSystem) chown(path, owner string) error { 29 if owner == "" { 30 return errors.New("Failed to lookup user ''") 31 } 32 33 var group string 34 var err error 35 36 ownerSplit := strings.Split(owner, ":") 37 user := ownerSplit[0] 38 39 if len(ownerSplit) <= 1 { 40 group, err = fs.runCommand(fmt.Sprintf("id -g %s", user)) 41 if err != nil { 42 return bosherr.WrapErrorf(err, "Failed to lookup user '%s'", user) 43 } 44 } else { 45 group = ownerSplit[1] 46 } 47 48 _, err = fs.runCommand(fmt.Sprintf("chown '%s:%s' '%s'", user, group, path)) 49 if err != nil { 50 return bosherr.WrapError(err, "Failed to chown") 51 } 52 53 return nil 54} 55 56func (fs *osFileSystem) symlinkPaths(oldPath, newPath string) (old, new string, err error) { 57 return oldPath, newPath, nil 58} 59