LEFT | RIGHT |
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 Loading... |
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 } |
LEFT | RIGHT |