This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
forked from goss-org/goss
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I've extracted the unix-only part to file_unix.go and windows part to file_windows.go. I haven't found an easy way to support owners/groups on windows, so I've left it empty. TODO: figure out how to write and run integration tests on windows, but probably not this pr.
- Loading branch information
1 parent
5453a57
commit a1eaf7a
Showing
3 changed files
with
93 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// +build !windows | ||
|
||
package system | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
"syscall" | ||
) | ||
|
||
func (f *DefFile) Mode() (string, error) { | ||
if err := f.setup(); err != nil { | ||
return "", err | ||
} | ||
|
||
fi, err := os.Lstat(f.realPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
sys := fi.Sys() | ||
stat := sys.(*syscall.Stat_t) | ||
mode := fmt.Sprintf("%04o", (stat.Mode & 07777)) | ||
return mode, nil | ||
} | ||
|
||
func (f *DefFile) Owner() (string, error) { | ||
if err := f.setup(); err != nil { | ||
return "", err | ||
} | ||
|
||
fi, err := os.Lstat(f.realPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
uidS := fmt.Sprint(fi.Sys().(*syscall.Stat_t).Uid) | ||
uid, err := strconv.Atoi(uidS) | ||
if err != nil { | ||
return "", err | ||
} | ||
return getUserForUid(uid) | ||
} | ||
|
||
func (f *DefFile) Group() (string, error) { | ||
if err := f.setup(); err != nil { | ||
return "", err | ||
} | ||
|
||
fi, err := os.Lstat(f.realPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
gidS := fmt.Sprint(fi.Sys().(*syscall.Stat_t).Gid) | ||
gid, err := strconv.Atoi(gidS) | ||
if err != nil { | ||
return "", err | ||
} | ||
return getGroupForGid(gid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package system | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Mode returns golang file mode. This method is cross-platform, but we are keeping unix-specific implementation | ||
// in file_unix.go for backwards compatibility. | ||
func (f *DefFile) Mode() (string, error) { | ||
if err := f.setup(); err != nil { | ||
return "", err | ||
} | ||
|
||
fi, err := os.Lstat(f.realPath) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
mode := fmt.Sprintf("%04o", (fi.Mode() & 07777)) | ||
return mode, nil | ||
} | ||
|
||
// TODO(ENG-1522): owner and group are not defined for windows in standard library, find out whether we can support it. | ||
func (f *DefFile) Owner() (string, error) { | ||
return "", nil | ||
} | ||
|
||
func (f *DefFile) Group() (string, error) { | ||
return "", nil | ||
} |