Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "errors"
- "fmt"
- "io/ioutil"
- "os"
- "time"
- "github.com/djherbis/atime"
- )
- var durations = []time.Duration{
- time.Nanosecond,
- time.Microsecond,
- time.Millisecond,
- }
- func main() {
- var errCounts = make([]int, len(durations))
- var succCounts = make([]int, len(durations))
- for j := 0; j < 3; j++ {
- for i := 1; i <= 100; i++ {
- err := checkAtimeSupport("/home/harsha", time.Duration(i)*durations[j])
- if err != nil {
- errCounts[j]++
- } else {
- succCounts[j]++
- }
- }
- }
- for j := 0; j < 3; j++ {
- fmt.Println("Errors:", errCounts[j], "Success:", succCounts[j], "Duration:", durations[j])
- }
- }
- // Return error if Atime is disabled on the O/S
- func checkAtimeSupport(dir string, delay time.Duration) (err error) {
- file, err := ioutil.TempFile(dir, "prefix")
- if err != nil {
- return err
- }
- fname := file.Name()
- defer os.Remove(fname)
- finfo1, err := os.Stat(fname)
- if err != nil {
- file.Close()
- return err
- }
- file.Close()
- time.Sleep(delay)
- if _, err = ioutil.ReadFile(fname); err != nil {
- return err
- }
- finfo2, err := os.Stat(fname)
- if atime.Get(finfo2).Equal(atime.Get(finfo1)) {
- return errors.New("Atime not supported")
- }
- return
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement