...

Source file src/k8s.io/kubernetes/pkg/volume/util/io_util.go

Documentation: k8s.io/kubernetes/pkg/volume/util

     1  /*
     2  Copyright 2016 The Kubernetes Authors.
     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  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package util
    18  
    19  import (
    20  	"io/ioutil"
    21  	"os"
    22  	"path/filepath"
    23  )
    24  
    25  // IoUtil is a mockable util for common IO operations
    26  type IoUtil interface {
    27  	ReadFile(filename string) ([]byte, error)
    28  	ReadDir(dirname string) ([]os.FileInfo, error)
    29  	Lstat(name string) (os.FileInfo, error)
    30  	EvalSymlinks(path string) (string, error)
    31  }
    32  
    33  type osIOHandler struct{}
    34  
    35  // NewIOHandler Create a new IoHandler implementation
    36  func NewIOHandler() IoUtil {
    37  	return &osIOHandler{}
    38  }
    39  
    40  func (handler *osIOHandler) ReadFile(filename string) ([]byte, error) {
    41  	return os.ReadFile(filename)
    42  }
    43  func (handler *osIOHandler) ReadDir(dirname string) ([]os.FileInfo, error) {
    44  	return ioutil.ReadDir(dirname)
    45  }
    46  func (handler *osIOHandler) Lstat(name string) (os.FileInfo, error) {
    47  	return os.Lstat(name)
    48  }
    49  func (handler *osIOHandler) EvalSymlinks(path string) (string, error) {
    50  	return filepath.EvalSymlinks(path)
    51  }
    52  

View as plain text