github.com/MRtecno98/afero@v1.9.3/os.go (about) 1 // Copyright © 2014 Steve Francia <spf@spf13.com>. 2 // Copyright 2013 tsuru authors. All rights reserved. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package afero 16 17 import ( 18 "os" 19 "time" 20 ) 21 22 var _ Lstater = (*OsFs)(nil) 23 24 // OsFs is a Fs implementation that uses functions provided by the os package. 25 // 26 // For details in any method, check the documentation of the os package 27 // (http://golang.org/pkg/os/). 28 type OsFs struct{} 29 30 func NewOsFs() Fs { 31 return &OsFs{} 32 } 33 34 func (OsFs) Name() string { return "OsFs" } 35 36 func (OsFs) Close() {} 37 38 func (OsFs) Create(name string) (File, error) { 39 f, e := os.Create(name) 40 if f == nil { 41 // while this looks strange, we need to return a bare nil (of type nil) not 42 // a nil value of type *os.File or nil won't be nil 43 return nil, e 44 } 45 return f, e 46 } 47 48 func (OsFs) Mkdir(name string, perm os.FileMode) error { 49 return os.Mkdir(name, perm) 50 } 51 52 func (OsFs) MkdirAll(path string, perm os.FileMode) error { 53 return os.MkdirAll(path, perm) 54 } 55 56 func (OsFs) Open(name string) (File, error) { 57 f, e := os.Open(name) 58 if f == nil { 59 // while this looks strange, we need to return a bare nil (of type nil) not 60 // a nil value of type *os.File or nil won't be nil 61 return nil, e 62 } 63 return f, e 64 } 65 66 func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) { 67 f, e := os.OpenFile(name, flag, perm) 68 if f == nil { 69 // while this looks strange, we need to return a bare nil (of type nil) not 70 // a nil value of type *os.File or nil won't be nil 71 return nil, e 72 } 73 return f, e 74 } 75 76 func (OsFs) Remove(name string) error { 77 return os.Remove(name) 78 } 79 80 func (OsFs) RemoveAll(path string) error { 81 return os.RemoveAll(path) 82 } 83 84 func (OsFs) Rename(oldname, newname string) error { 85 return os.Rename(oldname, newname) 86 } 87 88 func (OsFs) Stat(name string) (os.FileInfo, error) { 89 return os.Stat(name) 90 } 91 92 func (OsFs) Chmod(name string, mode os.FileMode) error { 93 return os.Chmod(name, mode) 94 } 95 96 func (OsFs) Chown(name string, uid, gid int) error { 97 return os.Chown(name, uid, gid) 98 } 99 100 func (OsFs) Chtimes(name string, atime time.Time, mtime time.Time) error { 101 return os.Chtimes(name, atime, mtime) 102 } 103 104 func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error) { 105 fi, err := os.Lstat(name) 106 return fi, true, err 107 } 108 109 func (OsFs) SymlinkIfPossible(oldname, newname string) error { 110 return os.Symlink(oldname, newname) 111 } 112 113 func (OsFs) ReadlinkIfPossible(name string) (string, error) { 114 return os.Readlink(name) 115 }