Dan Willemsen | ebae302 | 2017-01-13 23:01:08 -0800 | [diff] [blame] | 1 | // Copyright 2016 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris |
| 6 | |
| 7 | package os |
| 8 | |
| 9 | import ( |
| 10 | "syscall" |
| 11 | ) |
| 12 | |
| 13 | // Stat returns the FileInfo structure describing file. |
| 14 | // If there is an error, it will be of type *PathError. |
| 15 | func (f *File) Stat() (FileInfo, error) { |
| 16 | if f == nil { |
| 17 | return nil, ErrInvalid |
| 18 | } |
| 19 | var fs fileStat |
Dan Willemsen | d279748 | 2017-07-26 13:13:13 -0700 | [diff] [blame] | 20 | err := f.pfd.Fstat(&fs.sys) |
Dan Willemsen | ebae302 | 2017-01-13 23:01:08 -0800 | [diff] [blame] | 21 | if err != nil { |
| 22 | return nil, &PathError{"stat", f.name, err} |
| 23 | } |
| 24 | fillFileStatFromSys(&fs, f.name) |
| 25 | return &fs, nil |
| 26 | } |
| 27 | |
Dan Willemsen | a322328 | 2018-02-27 19:41:43 -0800 | [diff] [blame^] | 28 | // statNolog stats a file with no test logging. |
| 29 | func statNolog(name string) (FileInfo, error) { |
Dan Willemsen | ebae302 | 2017-01-13 23:01:08 -0800 | [diff] [blame] | 30 | var fs fileStat |
| 31 | err := syscall.Stat(name, &fs.sys) |
| 32 | if err != nil { |
| 33 | return nil, &PathError{"stat", name, err} |
| 34 | } |
| 35 | fillFileStatFromSys(&fs, name) |
| 36 | return &fs, nil |
| 37 | } |
| 38 | |
Dan Willemsen | a322328 | 2018-02-27 19:41:43 -0800 | [diff] [blame^] | 39 | // lstatNolog lstats a file with no test logging. |
| 40 | func lstatNolog(name string) (FileInfo, error) { |
Dan Willemsen | ebae302 | 2017-01-13 23:01:08 -0800 | [diff] [blame] | 41 | var fs fileStat |
| 42 | err := syscall.Lstat(name, &fs.sys) |
| 43 | if err != nil { |
| 44 | return nil, &PathError{"lstat", name, err} |
| 45 | } |
| 46 | fillFileStatFromSys(&fs, name) |
| 47 | return &fs, nil |
| 48 | } |