|
@@ -1,5 +1,3 @@
|
|
|
-// +build windows
|
|
|
-
|
|
|
package system
|
|
|
|
|
|
import (
|
|
@@ -8,18 +6,11 @@ import (
|
|
|
)
|
|
|
|
|
|
// StatT type contains status of a file. It contains metadata
|
|
|
-// like name, permission, size, etc about a file.
|
|
|
+// like permission, size, etc about a file.
|
|
|
type StatT struct {
|
|
|
- name string
|
|
|
- size int64
|
|
|
- mode os.FileMode
|
|
|
- modTime time.Time
|
|
|
- isDir bool
|
|
|
-}
|
|
|
-
|
|
|
-// Name returns file's name.
|
|
|
-func (s StatT) Name() string {
|
|
|
- return s.name
|
|
|
+ mode os.FileMode
|
|
|
+ size int64
|
|
|
+ mtim time.Time
|
|
|
}
|
|
|
|
|
|
// Size returns file's size.
|
|
@@ -29,15 +20,30 @@ func (s StatT) Size() int64 {
|
|
|
|
|
|
// Mode returns file's permission mode.
|
|
|
func (s StatT) Mode() os.FileMode {
|
|
|
- return s.mode
|
|
|
+ return os.FileMode(s.mode)
|
|
|
+}
|
|
|
+
|
|
|
+// Mtim returns file's last modification time.
|
|
|
+func (s StatT) Mtim() time.Time {
|
|
|
+ return time.Time(s.mtim)
|
|
|
}
|
|
|
|
|
|
-// ModTime returns file's last modification time.
|
|
|
-func (s StatT) ModTime() time.Time {
|
|
|
- return s.modTime
|
|
|
+// Stat takes a path to a file and returns
|
|
|
+// a system.StatT type pertaining to that file.
|
|
|
+//
|
|
|
+// Throws an error if the file does not exist
|
|
|
+func Stat(path string) (*StatT, error) {
|
|
|
+ fi, err := os.Stat(path)
|
|
|
+ if err != nil {
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+ return fromStatT(&fi)
|
|
|
}
|
|
|
|
|
|
-// IsDir returns whether file is actually a directory.
|
|
|
-func (s StatT) IsDir() bool {
|
|
|
- return s.isDir
|
|
|
+// fromStatT converts a os.FileInfo type to a system.StatT type
|
|
|
+func fromStatT(fi *os.FileInfo) (*StatT, error) {
|
|
|
+ return &StatT{
|
|
|
+ size: (*fi).Size(),
|
|
|
+ mode: (*fi).Mode(),
|
|
|
+ mtim: (*fi).ModTime()}, nil
|
|
|
}
|