Commit 5990f78f authored by Luke Champine's avatar Luke Champine

newJournal takes a contractorPersist arg

parent 523f0b2c
......@@ -78,10 +78,8 @@ type stdPersist struct {
func (p *stdPersist) save(data contractorPersist) error {
if p.journal == nil {
var err error
p.journal, err = newJournal(p.filename)
if err != nil {
return err
}
p.journal, err = newJournal(p.filename, data)
return err
}
return p.journal.checkpoint(data)
}
......@@ -95,7 +93,11 @@ func (p *stdPersist) load(data *contractorPersist) error {
p.journal, err = openJournal(p.filename, data)
if err != nil {
// try loading old persist
return loadv110persist(filepath.Dir(p.filename), data)
err = loadv110persist(filepath.Dir(p.filename), data)
if err != nil {
return err
}
p.journal, err = newJournal(p.filename, *data)
}
return err
}
......
......@@ -130,9 +130,8 @@ func (j *journal) Close() error {
return j.f.Close()
}
// newJournal creates a new journal, using an empty contractorPersist as the
// initial object.
func newJournal(filename string) (*journal, error) {
// newJournal creates a new journal, using data as the initial object.
func newJournal(filename string, data contractorPersist) (*journal, error) {
f, err := os.Create(filename)
if err != nil {
return nil, err
......@@ -142,13 +141,8 @@ func newJournal(filename string) (*journal, error) {
if err := enc.Encode(journalMeta); err != nil {
return nil, err
}
// write empty contractorPersist
initObj := contractorPersist{
CachedRevisions: map[string]cachedRevision{},
Contracts: map[string]modules.RenterContract{},
RenewedIDs: map[string]string{},
}
if err := enc.Encode(initObj); err != nil {
// write initial object
if err := enc.Encode(data); err != nil {
return nil, err
}
if err := f.Sync(); err != nil {
......
......@@ -28,7 +28,7 @@ func tempFile(t interface {
func tempJournal(t interface {
Fatal(...interface{})
}, name string) (*journal, func()) {
j, err := newJournal(filepath.Join(build.TempDir("contractor", name)))
j, err := newJournal(filepath.Join(build.TempDir("contractor", name)), contractorPersist{})
if err != nil {
t.Fatal(err)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment