Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2677)

Unified Diff: src/pkg/os/stat_linux.go

Issue 5416060: code review 5416060: io: new FileInfo, FileMode types + update tree (Closed)
Patch Set: diff -r d917a203b389 https://go.googlecode.com/hg/ Created 13 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/pkg/os/stat_freebsd.go ('k') | src/pkg/os/stat_openbsd.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/pkg/os/stat_linux.go
===================================================================
--- a/src/pkg/os/stat_linux.go
+++ b/src/pkg/os/stat_linux.go
@@ -9,31 +9,48 @@
"time"
)
-func isSymlink(stat *syscall.Stat_t) bool {
- return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK
+func sameFile(fs1, fs2 *FileStat) bool {
+ sys1 := fs1.Sys.(*syscall.Stat_t)
+ sys2 := fs2.Sys.(*syscall.Stat_t)
+ return sys1.Dev == sys2.Dev && sys1.Ino == sys2.Ino
}
-func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *FileInfo {
- fi.Dev = stat.Dev
- fi.Ino = stat.Ino
- fi.Nlink = uint64(stat.Nlink)
- fi.Mode = stat.Mode
- fi.Uid = int(stat.Uid)
- fi.Gid = int(stat.Gid)
- fi.Rdev = stat.Rdev
- fi.Size = stat.Size
- fi.Blksize = int64(stat.Blksize)
- fi.Blocks = stat.Blocks
- fi.AccessTime = timespecToTime(stat.Atim)
- fi.ModTime = timespecToTime(stat.Mtim)
- fi.ChangeTime = timespecToTime(stat.Ctim)
- fi.Name = basename(name)
- if isSymlink(lstat) && !isSymlink(stat) {
- fi.FollowedSymlink = true
+func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
+ fs := &FileStat{
+ name: basename(name),
+ size: int64(st.Size),
+ modTime: timespecToTime(st.Mtim),
+ Sys: st,
}
- return fi
+ fs.mode = FileMode(st.Mode & 0777)
+ switch st.Mode & syscall.S_IFMT {
+ case syscall.S_IFBLK, syscall.S_IFCHR:
+ fs.mode |= ModeDevice
+ case syscall.S_IFDIR:
+ fs.mode |= ModeDir
+ case syscall.S_IFIFO:
+ fs.mode |= ModeNamedPipe
+ case syscall.S_IFLNK:
+ fs.mode |= ModeSymlink
+ case syscall.S_IFREG:
+ // nothing to do
+ case syscall.S_IFSOCK:
+ fs.mode |= ModeSocket
+ }
+ if st.Mode&syscall.S_ISGID != 0 {
+ fs.mode |= ModeSetgid
+ }
+ if st.Mode&syscall.S_ISUID != 0 {
+ fs.mode |= ModeSetuid
+ }
+ return fs
}
func timespecToTime(ts syscall.Timespec) time.Time {
return time.Unix(int64(ts.Sec), int64(ts.Nsec))
}
+
+// For testing.
+func atime(fi FileInfo) time.Time {
+ return timespecToTime(fi.(*FileStat).Sys.(*syscall.Stat_t).Atim)
+}
« no previous file with comments | « src/pkg/os/stat_freebsd.go ('k') | src/pkg/os/stat_openbsd.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b