aboutsummaryrefslogtreecommitdiffstats
path: root/util/lamport/persisted_lamport.go
diff options
context:
space:
mode:
Diffstat (limited to 'util/lamport/persisted_lamport.go')
-rw-r--r--util/lamport/persisted_lamport.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/util/lamport/persisted_lamport.go b/util/lamport/persisted_lamport.go
index 4f12dd1b..22b23dcb 100644
--- a/util/lamport/persisted_lamport.go
+++ b/util/lamport/persisted_lamport.go
@@ -12,12 +12,19 @@ type Persisted struct {
filePath string
}
-func NewPersisted(filePath string) *Persisted {
+func NewPersisted(filePath string) (*Persisted, error) {
clock := &Persisted{
Clock: NewClock(),
filePath: filePath,
}
- return clock
+
+ dir := filepath.Dir(filePath)
+ err := os.MkdirAll(dir, 0777)
+ if err != nil {
+ return nil, err
+ }
+
+ return clock, nil
}
func LoadPersisted(filePath string) (*Persisted, error) {
@@ -67,12 +74,6 @@ func (c *Persisted) read() error {
}
func (c *Persisted) Write() error {
- dir := filepath.Dir(c.filePath)
- err := os.MkdirAll(dir, 0777)
- if err != nil {
- return err
- }
-
data := []byte(fmt.Sprintf("%d", c.counter))
return ioutil.WriteFile(c.filePath, data, 0644)
}