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

Delta Between Two Patch Sets: src/pkg/os/stat_darwin.go

Issue 5416060: code review 5416060: io: new FileInfo, FileMode types + update tree (Closed)
Left Patch Set: diff -r 0c75ae21c217 https://go.googlecode.com/hg/ Created 13 years, 4 months ago
Right Patch Set: diff -r d917a203b389 https://go.googlecode.com/hg/ Created 13 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/os/path.go ('k') | src/pkg/os/stat_freebsd.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package os 5 package os
6 6
7 import ( 7 import (
8 "syscall" 8 "syscall"
9 "time" 9 "time"
10 ) 10 )
11 11
12 func isSymlink(stat *syscall.Stat_t) bool { 12 func sameFile(fs1, fs2 *FileStat) bool {
13 » return stat.Mode&syscall.S_IFMT == syscall.S_IFLNK 13 » sys1 := fs1.Sys.(*syscall.Stat_t)
14 » sys2 := fs2.Sys.(*syscall.Stat_t)
15 » return sys1.Dev == sys2.Dev && sys1.Ino == sys2.Ino
14 } 16 }
15 17
16 func fileInfoFromStat(name string, fi *FileInfo, lstat, stat *syscall.Stat_t) *F ileInfo { 18 func fileInfoFromStat(st *syscall.Stat_t, name string) FileInfo {
17 » fi.Dev = uint64(stat.Dev) 19 » fs := &FileStat{
18 » fi.Ino = stat.Ino 20 » » name: basename(name),
19 » fi.Nlink = uint64(stat.Nlink) 21 » » size: int64(st.Size),
20 » fi.Mode = uint32(stat.Mode) 22 » » modTime: timespecToTime(st.Mtimespec),
21 » fi.Uid = int(stat.Uid) 23 » » Sys: st,
22 » fi.Gid = int(stat.Gid)
23 » fi.Rdev = uint64(stat.Rdev)
24 » fi.Size = stat.Size
25 » fi.Blksize = int64(stat.Blksize)
26 » fi.Blocks = stat.Blocks
27 » fi.AccessTime = timespecToTime(stat.Atimespec)
28 » fi.ModTime = timespecToTime(stat.Mtimespec)
29 » fi.ChangeTime = timespecToTime(stat.Ctimespec)
30 » fi.Name = basename(name)
31 » if isSymlink(lstat) && !isSymlink(stat) {
32 » » fi.FollowedSymlink = true
33 } 24 }
34 » return fi 25 » fs.mode = FileMode(st.Mode & 0777)
26 » switch st.Mode & syscall.S_IFMT {
27 » case syscall.S_IFBLK, syscall.S_IFCHR, syscall.S_IFWHT:
28 » » fs.mode |= ModeDevice
29 » case syscall.S_IFDIR:
30 » » fs.mode |= ModeDir
31 » case syscall.S_IFIFO:
32 » » fs.mode |= ModeNamedPipe
33 » case syscall.S_IFLNK:
34 » » fs.mode |= ModeSymlink
35 » case syscall.S_IFREG:
36 » » // nothing to do
37 » case syscall.S_IFSOCK:
38 » » fs.mode |= ModeSocket
39 » }
40 » if st.Mode&syscall.S_ISGID != 0 {
41 » » fs.mode |= ModeSetgid
42 » }
43 » if st.Mode&syscall.S_ISUID != 0 {
44 » » fs.mode |= ModeSetuid
45 » }
46 » return fs
35 } 47 }
36 48
37 func timespecToTime(ts syscall.Timespec) time.Time { 49 func timespecToTime(ts syscall.Timespec) time.Time {
38 return time.Unix(int64(ts.Sec), int64(ts.Nsec)) 50 return time.Unix(int64(ts.Sec), int64(ts.Nsec))
39 } 51 }
52
53 // For testing.
54 func atime(fi FileInfo) time.Time {
55 return timespecToTime(fi.(*FileStat).Sys.(*syscall.Stat_t).Atimespec)
56 }
LEFTRIGHT

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