github.com/anakojm/hugo-katex@v0.0.0-20231023141351-42d6f5de9c0b/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  	errNoOp          = errors.New("this is a filesystem that does nothing and this operation is not supported")
    26  	_       afero.Fs = (*noOpFs)(nil)
    27  
    28  	// NoOpFs provides a no-op filesystem that implements the afero.Fs
    29  	// interface.
    30  	NoOpFs = &noOpFs{}
    31  )
    32  
    33  type noOpFs struct {
    34  }
    35  
    36  func (fs noOpFs) Create(name string) (afero.File, error) {
    37  	panic(errNoOp)
    38  }
    39  
    40  func (fs noOpFs) Mkdir(name string, perm os.FileMode) error {
    41  	return nil
    42  }
    43  
    44  func (fs noOpFs) MkdirAll(path string, perm os.FileMode) error {
    45  	return nil
    46  }
    47  
    48  func (fs noOpFs) Open(name string) (afero.File, error) {
    49  	return nil, os.ErrNotExist
    50  }
    51  
    52  func (fs noOpFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
    53  	return nil, os.ErrNotExist
    54  }
    55  
    56  func (fs noOpFs) Remove(name string) error {
    57  	return nil
    58  }
    59  
    60  func (fs noOpFs) RemoveAll(path string) error {
    61  	return nil
    62  }
    63  
    64  func (fs noOpFs) Rename(oldname string, newname string) error {
    65  	panic(errNoOp)
    66  }
    67  
    68  func (fs noOpFs) Stat(name string) (os.FileInfo, error) {
    69  	return nil, os.ErrNotExist
    70  }
    71  
    72  func (fs noOpFs) Name() string {
    73  	return "noOpFs"
    74  }
    75  
    76  func (fs noOpFs) Chmod(name string, mode os.FileMode) error {
    77  	panic(errNoOp)
    78  }
    79  
    80  func (fs noOpFs) Chtimes(name string, atime time.Time, mtime time.Time) error {
    81  	panic(errNoOp)
    82  }
    83  
    84  func (fs *noOpFs) Chown(name string, uid int, gid int) error {
    85  	panic(errNoOp)
    86  }