Path: blob/main/vendor/github.com/spf13/afero/os.go
2875 views
// Copyright © 2014 Steve Francia <[email protected]>.1// Copyright 2013 tsuru authors. All rights reserved.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314package afero1516import (17"os"18"time"19)2021var _ Lstater = (*OsFs)(nil)2223// OsFs is a Fs implementation that uses functions provided by the os package.24//25// For details in any method, check the documentation of the os package26// (http://golang.org/pkg/os/).27type OsFs struct{}2829func NewOsFs() Fs {30return &OsFs{}31}3233func (OsFs) Name() string { return "OsFs" }3435func (OsFs) Create(name string) (File, error) {36f, e := os.Create(name)37if f == nil {38// while this looks strange, we need to return a bare nil (of type nil) not39// a nil value of type *os.File or nil won't be nil40return nil, e41}42return f, e43}4445func (OsFs) Mkdir(name string, perm os.FileMode) error {46return os.Mkdir(name, perm)47}4849func (OsFs) MkdirAll(path string, perm os.FileMode) error {50return os.MkdirAll(path, perm)51}5253func (OsFs) Open(name string) (File, error) {54f, e := os.Open(name)55if f == nil {56// while this looks strange, we need to return a bare nil (of type nil) not57// a nil value of type *os.File or nil won't be nil58return nil, e59}60return f, e61}6263func (OsFs) OpenFile(name string, flag int, perm os.FileMode) (File, error) {64f, e := os.OpenFile(name, flag, perm)65if f == nil {66// while this looks strange, we need to return a bare nil (of type nil) not67// a nil value of type *os.File or nil won't be nil68return nil, e69}70return f, e71}7273func (OsFs) Remove(name string) error {74return os.Remove(name)75}7677func (OsFs) RemoveAll(path string) error {78return os.RemoveAll(path)79}8081func (OsFs) Rename(oldname, newname string) error {82return os.Rename(oldname, newname)83}8485func (OsFs) Stat(name string) (os.FileInfo, error) {86return os.Stat(name)87}8889func (OsFs) Chmod(name string, mode os.FileMode) error {90return os.Chmod(name, mode)91}9293func (OsFs) Chown(name string, uid, gid int) error {94return os.Chown(name, uid, gid)95}9697func (OsFs) Chtimes(name string, atime time.Time, mtime time.Time) error {98return os.Chtimes(name, atime, mtime)99}100101func (OsFs) LstatIfPossible(name string) (os.FileInfo, bool, error) {102fi, err := os.Lstat(name)103return fi, true, err104}105106func (OsFs) SymlinkIfPossible(oldname, newname string) error {107return os.Symlink(oldname, newname)108}109110func (OsFs) ReadlinkIfPossible(name string) (string, error) {111return os.Readlink(name)112}113114115