feat: Use portable syscall.Stat_t equivalent for FileInfo

This commit is contained in:
Felicitas Pojtinger
2022-01-15 20:58:47 +01:00
parent 1cf9416bce
commit c5ce6d6cd3
4 changed files with 38 additions and 1 deletions

View File

@@ -121,11 +121,22 @@ func (f *File) syncWithoutLocking() error {
return config.FileConfig{}, err
}
// Some OSes like i.e. Windows don't support numeric GIDs and UIDs, so use 0 instead
gid := 0
uid := 0
sys, ok := f.info.Sys().(*Stat)
if ok {
gid = int(sys.Gid)
uid = int(sys.Uid)
}
f.info = NewFileInfo(
f.info.Name(),
size,
f.info.Mode(),
f.info.ModTime(),
gid,
uid,
f.info.IsDir(),
f.log,
)

View File

@@ -0,0 +1,8 @@
//go:build windows
package fs
type Stat struct {
Uid uint32
Gid uint32
}

7
internal/fs/file_unix.go Normal file
View File

@@ -0,0 +1,7 @@
//go:build !windows
package fs
import "syscall"
type Stat syscall.Stat_t

View File

@@ -16,6 +16,8 @@ type FileInfo struct {
size int64
mode fs.FileMode
modTime time.Time
gid int
uid int
isDir bool
log logging.StructuredLogger
@@ -26,6 +28,8 @@ func NewFileInfo(
size int64,
mode fs.FileMode,
modTime time.Time,
gid int,
uid int,
isDir bool,
log logging.StructuredLogger,
@@ -35,6 +39,8 @@ func NewFileInfo(
size: size,
mode: mode,
modTime: modTime,
gid: gid,
uid: uid,
isDir: isDir,
log: log,
@@ -51,6 +57,8 @@ func NewFileInfoFromTarHeader(
size: hdr.FileInfo().Size(),
mode: hdr.FileInfo().Mode(),
modTime: hdr.FileInfo().ModTime(),
gid: hdr.Gid,
uid: hdr.Uid,
isDir: hdr.FileInfo().IsDir(),
log: log,
@@ -102,5 +110,8 @@ func (f *FileInfo) Sys() interface{} {
"name": f.name,
})
return nil
return &Stat{
Uid: uint32(f.uid),
Gid: uint32(f.gid),
}
}