2022-03-28 20:23:47 +00:00
|
|
|
//go:build !windows
|
2019-05-04 08:34:28 +00:00
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package archiver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type wrappedFileInfo struct {
|
|
|
|
os.FileInfo
|
|
|
|
sys interface{}
|
|
|
|
mode os.FileMode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi wrappedFileInfo) Sys() interface{} {
|
|
|
|
return fi.sys
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fi wrappedFileInfo) Mode() os.FileMode {
|
|
|
|
return fi.mode
|
|
|
|
}
|
|
|
|
|
|
|
|
// wrapFileInfo returns a new os.FileInfo with the mode, owner, and group fields changed.
|
2019-05-05 12:57:38 +00:00
|
|
|
func wrapFileInfo(t testing.TB, fi os.FileInfo) os.FileInfo {
|
2019-05-04 08:34:28 +00:00
|
|
|
// get the underlying stat_t and modify the values
|
|
|
|
stat := fi.Sys().(*syscall.Stat_t)
|
2019-05-05 12:57:38 +00:00
|
|
|
stat.Mode = mockFileInfoMode
|
|
|
|
stat.Uid = mockFileInfoUID
|
|
|
|
stat.Gid = mockFileInfoGID
|
2019-05-04 08:34:28 +00:00
|
|
|
|
|
|
|
// wrap the os.FileInfo so we can return a modified stat_t
|
|
|
|
res := wrappedFileInfo{
|
|
|
|
FileInfo: fi,
|
|
|
|
sys: stat,
|
2019-05-05 12:57:38 +00:00
|
|
|
mode: mockFileInfoMode,
|
2019-05-04 08:34:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|