storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/disk-cache-check-support_other.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  /*
     5   * MinIO Cloud Storage, (C) 2019-2020 MinIO, Inc.
     6   *
     7   * Licensed under the Apache License, Version 2.0 (the "License");
     8   * you may not use this file except in compliance with the License.
     9   * You may obtain a copy of the License at
    10   *
    11   *     http://www.apache.org/licenses/LICENSE-2.0
    12   *
    13   * Unless required by applicable law or agreed to in writing, software
    14   * distributed under the License is distributed on an "AS IS" BASIS,
    15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16   * See the License for the specific language governing permissions and
    17   * limitations under the License.
    18   */
    19  
    20  package cmd
    21  
    22  import (
    23  	"errors"
    24  	"io"
    25  	"io/ioutil"
    26  	"os"
    27  	"time"
    28  
    29  	"github.com/djherbis/atime"
    30  )
    31  
    32  // Return error if Atime is disabled on the O/S
    33  func checkAtimeSupport(dir string) (err error) {
    34  	file, err := ioutil.TempFile(dir, "prefix")
    35  	if err != nil {
    36  		return
    37  	}
    38  	defer os.Remove(file.Name())
    39  	defer file.Close()
    40  	finfo1, err := os.Stat(file.Name())
    41  	if err != nil {
    42  		return
    43  	}
    44  	// add a sleep to ensure atime change is detected
    45  	time.Sleep(10 * time.Millisecond)
    46  
    47  	if _, err = io.Copy(ioutil.Discard, file); err != nil {
    48  		return
    49  	}
    50  
    51  	finfo2, err := os.Stat(file.Name())
    52  
    53  	if atime.Get(finfo2).Equal(atime.Get(finfo1)) {
    54  		return errors.New("Atime not supported")
    55  	}
    56  	return
    57  }