exploit the embedded FileStat in fileInfo

This commit is contained in:
Cassondra Foesch 2021-08-11 13:20:30 +00:00
parent b64dfe1710
commit 0f6e8d5016
1 changed files with 13 additions and 20 deletions

View File

@ -21,29 +21,26 @@ const (
// fileInfo is an artificial type designed to satisfy os.FileInfo.
type fileInfo struct {
name string
size int64
mode os.FileMode
mtime time.Time
sys interface{}
name string
stat *FileStat
}
// Name returns the base name of the file.
func (fi *fileInfo) Name() string { return fi.name }
// Size returns the length in bytes for regular files; system-dependent for others.
func (fi *fileInfo) Size() int64 { return fi.size }
func (fi *fileInfo) Size() int64 { return int64(fi.stat.Size) }
// Mode returns file mode bits.
func (fi *fileInfo) Mode() os.FileMode { return fi.mode }
func (fi *fileInfo) Mode() os.FileMode { return toFileMode(fi.stat.Mode) }
// ModTime returns the last modification time of the file.
func (fi *fileInfo) ModTime() time.Time { return fi.mtime }
func (fi *fileInfo) ModTime() time.Time { return time.Unix(int64(fi.stat.Mtime), 0) }
// IsDir returns true if the file is a directory.
func (fi *fileInfo) IsDir() bool { return fi.Mode().IsDir() }
func (fi *fileInfo) Sys() interface{} { return fi.sys }
func (fi *fileInfo) Sys() interface{} { return fi.stat }
// FileStat holds the original unmarshalled values from a call to READDIR or
// *STAT. It is exported for the purposes of accessing the raw values via
@ -65,25 +62,21 @@ type StatExtended struct {
ExtData string
}
func fileInfoFromStat(st *FileStat, name string) os.FileInfo {
fs := &fileInfo{
name: name,
size: int64(st.Size),
mode: toFileMode(st.Mode),
mtime: time.Unix(int64(st.Mtime), 0),
sys: st,
func fileInfoFromStat(stat *FileStat, name string) os.FileInfo {
return &fileInfo{
name: name,
stat: stat,
}
return fs
}
func fileStatFromInfo(fi os.FileInfo) (uint32, FileStat) {
func fileStatFromInfo(fi os.FileInfo) (uint32, *FileStat) {
mtime := fi.ModTime().Unix()
atime := mtime
var flags uint32 = sshFileXferAttrSize |
sshFileXferAttrPermissions |
sshFileXferAttrACmodTime
fileStat := FileStat{
fileStat := &FileStat{
Size: uint64(fi.Size()),
Mode: fromFileMode(fi.Mode()),
Mtime: uint32(mtime),
@ -91,7 +84,7 @@ func fileStatFromInfo(fi os.FileInfo) (uint32, FileStat) {
}
// os specific file stat decoding
fileStatFromInfoOs(fi, &flags, &fileStat)
fileStatFromInfoOs(fi, &flags, fileStat)
return flags, fileStat
}