Created
July 8, 2019 22:54
-
-
Save harshavardhana/0aff51f63a63059b3ebbd0c172e40872 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Author
harshavardhana
commented
Jul 8, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment