...

Source file src/github.com/GoogleCloudPlatform/k8s-config-connector/pkg/vfsgen/consistent_mod_time_file_system.go

Documentation: github.com/GoogleCloudPlatform/k8s-config-connector/pkg/vfsgen

     1  // Copyright 2022 Google LLC
     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  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package vfsgen
    16  
    17  import (
    18  	"net/http"
    19  	"os"
    20  	"time"
    21  )
    22  
    23  // consistentModTimeFileSystem is a wrapper for http.FileSystem. The value returned by the ModTime() function is the
    24  // 'empty' time value. In doing so, it ensures that the output of vfsgen.Generate(...) is consistent with regards to
    25  // the time at which Generate(...) is run.
    26  type ConsistentModTimeFileSystem struct {
    27  	HttpFS http.FileSystem
    28  }
    29  
    30  type ConsistentModTimeFile struct {
    31  	http.File
    32  }
    33  
    34  type ConsistentModTimeFileInfo struct {
    35  	os.FileInfo
    36  }
    37  
    38  func (fs ConsistentModTimeFileSystem) Open(name string) (http.File, error) {
    39  	file, err := fs.HttpFS.Open(name)
    40  	if err != nil {
    41  		return nil, err
    42  	}
    43  	return ConsistentModTimeFile{File: file}, nil
    44  }
    45  
    46  func (f ConsistentModTimeFile) Stat() (os.FileInfo, error) {
    47  	fileInfo, err := f.File.Stat()
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  	return ConsistentModTimeFileInfo{FileInfo: fileInfo}, nil
    52  }
    53  
    54  func (f ConsistentModTimeFileInfo) ModTime() time.Time {
    55  	return time.Time{}
    56  }
    57  

View as plain text