2009-06-04 14:33:57 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package os
|
|
|
|
|
2011-11-30 10:01:46 -07:00
|
|
|
import (
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
)
|
2009-06-04 14:33:57 -06:00
|
|
|
|
|
|
|
func isSymlink(stat *syscall.Stat_t) bool {
|
2009-11-09 22:23:52 -07:00
|
|
|
return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK
|
2009-06-04 14:33:57 -06:00
|
|
|
}
|
|
|
|
|
2010-04-09 12:36:40 -06:00
|
|
|
func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo {
|
|
|
|
fi.Dev = uint64(stat.Dev)
|
|
|
|
fi.Ino = stat.Ino
|
|
|
|
fi.Nlink = uint64(stat.Nlink)
|
|
|
|
fi.Mode = uint32(stat.Mode)
|
2010-04-22 15:01:33 -06:00
|
|
|
fi.Uid = int(stat.Uid)
|
|
|
|
fi.Gid = int(stat.Gid)
|
2010-04-09 12:36:40 -06:00
|
|
|
fi.Rdev = uint64(stat.Rdev)
|
2010-04-22 15:01:33 -06:00
|
|
|
fi.Size = stat.Size
|
|
|
|
fi.Blksize = int64(stat.Blksize)
|
|
|
|
fi.Blocks = stat.Blocks
|
2011-11-30 10:01:46 -07:00
|
|
|
fi.AccessTime = timespecToTime(stat.Atimespec)
|
|
|
|
fi.ModTime = timespecToTime(stat.Mtimespec)
|
|
|
|
fi.ChangeTime = timespecToTime(stat.Ctimespec)
|
2011-03-29 12:23:36 -06:00
|
|
|
fi.Name = basename(name)
|
2009-06-04 14:33:57 -06:00
|
|
|
if isSymlink(lstat) && !isSymlink(stat) {
|
2010-04-09 12:36:40 -06:00
|
|
|
fi.FollowedSymlink = true
|
2009-06-04 14:33:57 -06:00
|
|
|
}
|
2010-04-09 12:36:40 -06:00
|
|
|
return fi
|
2009-06-04 14:33:57 -06:00
|
|
|
}
|
2011-11-30 10:01:46 -07:00
|
|
|
|
|
|
|
func timespecToTime(ts syscall.Timespec) time.Time {
|
|
|
|
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
|
|
|
|
}
|