()
| 70 | } |
| 71 | |
| 72 | func (pc *PersistedClock) read() error { |
| 73 | f, err := pc.root.Open(pc.filePath) |
| 74 | if os.IsNotExist(err) { |
| 75 | return ErrClockNotExist |
| 76 | } |
| 77 | if err != nil { |
| 78 | return err |
| 79 | } |
| 80 | |
| 81 | content, err := io.ReadAll(f) |
| 82 | if err != nil { |
| 83 | _ = f.Close() |
| 84 | return err |
| 85 | } |
| 86 | |
| 87 | err = f.Close() |
| 88 | if err != nil { |
| 89 | return err |
| 90 | } |
| 91 | |
| 92 | var value uint64 |
| 93 | n, err := fmt.Sscanf(string(content), "%d", &value) |
| 94 | if err != nil { |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | if n != 1 { |
| 99 | return fmt.Errorf("could not read the clock") |
| 100 | } |
| 101 | |
| 102 | pc.MemClock = NewMemClockWithTime(value) |
| 103 | |
| 104 | return nil |
| 105 | } |
| 106 | |
| 107 | func (pc *PersistedClock) Write() error { |
| 108 | data := []byte(fmt.Sprintf("%d", pc.counter)) |
no test coverage detected