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

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

Issue 6905057: code review 6905057: os: Improve the accuracy of os.Chtimes (Closed)
Left Patch Set: diff -r 6b602ab487d6 https://code.google.com/p/go Created 11 years, 3 months ago
Right Patch Set: diff -r ac06fe42df6d https://code.google.com/p/go Created 11 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/syscall/syscall_bsd.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
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 // +build darwin freebsd linux netbsd openbsd windows 5 // +build darwin freebsd linux netbsd openbsd windows
6 6
7 package os 7 package os
8 8
9 import ( 9 import (
10 "syscall" 10 "syscall"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return nil 146 return nil
147 } 147 }
148 148
149 // Chtimes changes the access and modification times of the named 149 // Chtimes changes the access and modification times of the named
150 // file, similar to the Unix utime() or utimes() functions. 150 // file, similar to the Unix utime() or utimes() functions.
151 // 151 //
152 // The underlying filesystem may truncate or round the values to a 152 // The underlying filesystem may truncate or round the values to a
153 // less precise time unit. 153 // less precise time unit.
154 // If there is an error, it will be of type *PathError. 154 // If there is an error, it will be of type *PathError.
155 func Chtimes(name string, atime time.Time, mtime time.Time) error { 155 func Chtimes(name string, atime time.Time, mtime time.Time) error {
156 » if syscall.ImplementsUtimens { 156 » var utimes [2]syscall.Timespec
157 » » var utimes [2]syscall.Timespec 157 » utimes[0] = syscall.NsecToTimespec(atime.UnixNano())
158 » » utimes[0] = syscall.NsecToTimespec(atime.UnixNano()) 158 » utimes[1] = syscall.NsecToTimespec(mtime.UnixNano())
159 » » utimes[1] = syscall.NsecToTimespec(mtime.UnixNano()) 159 » if e := syscall.UtimesNano(name, utimes[0:]); e != nil {
160 » » if e := syscall.Utimens(name, utimes[0:]); e != nil {
161 » » » // If not implemented or not supported then
162 » » » // fallback to utimes()
163 » » » if e != syscall.ENOSYS && e != syscall.ENOTSUP {
164 » » » » return &PathError{"chtimes", name, e}
165 » » » }
166 » » } else {
167 » » » return nil
168 » » }
169 » }
170 » var utimes [2]syscall.Timeval
171 » atime_ns := atime.Unix()*1e9 + int64(atime.Nanosecond())
172 » mtime_ns := mtime.Unix()*1e9 + int64(mtime.Nanosecond())
173 » utimes[0] = syscall.NsecToTimeval(atime_ns)
174 » utimes[1] = syscall.NsecToTimeval(mtime_ns)
175 » if e := syscall.Utimes(name, utimes[0:]); e != nil {
176 return &PathError{"chtimes", name, e} 160 return &PathError{"chtimes", name, e}
177 } 161 }
178 return nil 162 return nil
179 } 163 }
LEFTRIGHT

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