github.com/IBM/fsgo@v0.0.0-20220920202152-e16fd2119d49/fsgo.go (about)

     1  // Copyright 2022 IBM Inc. All rights reserved
     2  // Copyright © 2014 Steve Francia <spf@spf13.com>.
     3  // Copyright 2013 tsuru authors. All rights reserved.
     4  //
     5  // SPDX-License-Identifier: Apache2.0
     6  package fsgo
     7  
     8  import (
     9  	"errors"
    10  	"io"
    11  	"os"
    12  	"time"
    13  )
    14  
    15  type FsGo struct {
    16  	Fs
    17  }
    18  
    19  // File represents a file in the filesystem.
    20  type File interface {
    21  	io.Closer
    22  	io.Reader
    23  	io.ReaderAt
    24  	io.Seeker
    25  	io.Writer
    26  	io.WriterAt
    27  
    28  	Name() string
    29  	Readdir(count int) ([]os.FileInfo, error)
    30  	Readdirnames(n int) ([]string, error)
    31  	Stat() (os.FileInfo, error)
    32  	Sync() error
    33  	Truncate(size int64) error
    34  	WriteString(s string) (ret int, err error)
    35  }
    36  
    37  // Fs is the filesystem interface.
    38  //
    39  // Any simulated or real filesystem should implement this interface.
    40  type Fs interface {
    41  	// Create creates a file in the filesystem, returning the file and an
    42  	// error, if any happens.
    43  	Create(name string) (File, error)
    44  
    45  	// Mkdir creates a directory in the filesystem, return an error if any
    46  	// happens.
    47  	Mkdir(name string, perm os.FileMode) error
    48  
    49  	// MkdirAll creates a directory path and all parents that does not exist
    50  	// yet.
    51  	MkdirAll(path string, perm os.FileMode) error
    52  
    53  	// Open opens a file, returning it or an error, if any happens.
    54  	Open(name string) (File, error)
    55  
    56  	// OpenFile opens a file using the given flags and the given mode.
    57  	OpenFile(name string, flag int, perm os.FileMode) (File, error)
    58  
    59  	// Remove removes a file identified by name, returning an error, if any
    60  	// happens.
    61  	Remove(name string) error
    62  
    63  	// RemoveAll removes a directory path and any children it contains. It
    64  	// does not fail if the path does not exist (return nil).
    65  	RemoveAll(path string) error
    66  
    67  	// Rename renames a file.
    68  	Rename(oldname, newname string) error
    69  
    70  	// Stat returns a FileInfo describing the named file, or an error, if any
    71  	// happens.
    72  	Stat(name string) (os.FileInfo, error)
    73  
    74  	// The name of this FileSystem
    75  	Name() string
    76  
    77  	// Chmod changes the mode of the named file to mode.
    78  	Chmod(name string, mode os.FileMode) error
    79  
    80  	// Chown changes the uid and gid of the named file.
    81  	Chown(name string, uid, gid int) error
    82  
    83  	//Chtimes changes the access and modification times of the named file
    84  	Chtimes(name string, atime time.Time, mtime time.Time) error
    85  }
    86  
    87  var (
    88  	ErrFileClosed        = errors.New("File is closed")
    89  	ErrOutOfRange        = errors.New("out of range")
    90  	ErrTooLarge          = errors.New("too large")
    91  	ErrFileNotFound      = os.ErrNotExist
    92  	ErrFileExists        = os.ErrExist
    93  	ErrDestinationExists = os.ErrExist
    94  )