~rbn/neinp

ref: 314a874f1439902314753295580dc8ef3083fde8 neinp/stat/fileinfo.go -rw-r--r-- 713 bytes
314a874fAaron Bieber Split FileInfo into separate files that can be used per OS. 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package stat // import "go.rbn.im/neinp/stat"

import (
	"os"

	"go.rbn.im/neinp/qid"
)

// FileInfo creates Stat using os.FileInfo.Sys(). If using the information
// returned by Sys() fails, it returns a stat like returned by GenericStat.
func FileInfo(fi os.FileInfo) Stat {
	return fileInfo(fi)
}

// Generic creates a neinp.Stat not using FileInfo.Sys().
func Generic(fi os.FileInfo) Stat {
	size := fi.Size()
	if fi.IsDir() {
		size = 0
	}

	uid := "nobody"
	gid := "nogroup"

	stat := Stat{
		Qid:    qid.FileInfo(fi),
		Mode:   NeinMode(fi.Mode()),
		Atime:  fi.ModTime(),
		Mtime:  fi.ModTime(),
		Length: uint64(size),
		Name:   fi.Name(),
		Uid:    uid,
		Gid:    gid,
		Muid:   uid,
	}

	return stat
}