github.com/jmooring/hugo@v0.47.1/hugofs/noop_fs.go (about)

     1  // Copyright 2018 The Hugo 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 at
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // 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 and
    12  // limitations under the License.
    13  
    14  package hugofs
    15  
    16  import (
    17  	"errors"
    18  	"os"
    19  	"time"
    20  
    21  	"github.com/spf13/afero"
    22  )
    23  
    24  var (
    25  	noOpErr          = errors.New("this is a filesystem that does nothing and this operation is not supported")
    26  	_       afero.Fs = (*noOpFs)(nil)
    27  	NoOpFs           = &noOpFs{}
    28  )
    29  
    30  type noOpFs struct {
    31  }
    32  
    33  func (fs noOpFs) Create(name string) (afero.File, error) {
    34  	return nil, noOpErr
    35  }
    36  
    37  func (fs noOpFs) Mkdir(name string, perm os.FileMode) error {
    38  	return noOpErr
    39  }
    40  
    41  func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
    42  	return noOpErr
    43  }
    44  
    45  func (fs noOpFs) Open(name string) (afero.File, error) {
    46  	return nil, os.ErrNotExist
    47  }
    48  
    49  func (fs noOpFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
    50  	return nil, os.ErrNotExist
    51  }
    52  
    53  func (fs noOpFs) Remove(name string) error {
    54  	return noOpErr
    55  }
    56  
    57  func (fs noOpFs) RemoveAll(path string) error {
    58  	return noOpErr
    59  }
    60  
    61  func (fs noOpFs) Rename(oldname string, newname string) error {
    62  	return noOpErr
    63  }
    64  
    65  func (fs noOpFs) Stat(name string) (os.FileInfo, error) {
    66  	return nil, os.ErrNotExist
    67  }
    68  
    69  func (fs noOpFs) Name() string {
    70  	return "noOpFs"
    71  }
    72  
    73  func (fs noOpFs) Chmod(name string, mode os.FileMode) error {
    74  	return noOpErr
    75  }
    76  
    77  func (fs noOpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
    78  	return noOpErr
    79  }