Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "errors"
  5. "fmt"
  6. "io/ioutil"
  7. "os"
  8. "time"
  9.  
  10. "github.com/djherbis/atime"
  11. )
  12.  
  13. var durations = []time.Duration{
  14. time.Nanosecond,
  15. time.Microsecond,
  16. time.Millisecond,
  17. }
  18.  
  19. func main() {
  20. var errCounts = make([]int, len(durations))
  21. var succCounts = make([]int, len(durations))
  22. for j := 0; j < 3; j++ {
  23. for i := 1; i <= 100; i++ {
  24. err := checkAtimeSupport("/home/harsha", time.Duration(i)*durations[j])
  25. if err != nil {
  26. errCounts[j]++
  27. } else {
  28. succCounts[j]++
  29. }
  30. }
  31. }
  32. for j := 0; j < 3; j++ {
  33. fmt.Println("Errors:", errCounts[j], "Success:", succCounts[j], "Duration:", durations[j])
  34. }
  35. }
  36.  
  37. // Return error if Atime is disabled on the O/S
  38. func checkAtimeSupport(dir string, delay time.Duration) (err error) {
  39. file, err := ioutil.TempFile(dir, "prefix")
  40. if err != nil {
  41. return err
  42. }
  43.  
  44. fname := file.Name()
  45. defer os.Remove(fname)
  46.  
  47. finfo1, err := os.Stat(fname)
  48. if err != nil {
  49. file.Close()
  50. return err
  51. }
  52. file.Close()
  53.  
  54. time.Sleep(delay)
  55. if _, err = ioutil.ReadFile(fname); err != nil {
  56. return err
  57. }
  58.  
  59. finfo2, err := os.Stat(fname)
  60. if atime.Get(finfo2).Equal(atime.Get(finfo1)) {
  61. return errors.New("Atime not supported")
  62. }
  63. return
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement