Commit f7b99ece authored by Joan Piles's avatar Joan Piles

moved reusing from function to method

parent 31c32ead
......@@ -59,13 +59,12 @@ func runRsyncCommand(cmd *exec.Cmd) (error, chan error) {
func CreateSnapshot(base *Snapshot) (*Snapshot, error) {
cl := new(realClock)
partial := LastReusableFromDisk(cl)
newSn := LastReusableFromDisk(cl)
var newSn *Snapshot
if partial == nil {
if newSn == nil {
newSn = newIncompleteSnapshot(cl)
} else {
newSn = ReusePartial(partial, cl)
newSn.transIncomplete(cl)
}
cmd := createRsyncCommand(newSn, base)
err, done := runRsyncCommand(cmd)
......
......@@ -154,6 +154,21 @@ func (s *Snapshot) transPurging() {
}
}
// transIncomplete generates a new incomplete snapshot based on a previous one.
// Can be used to try to use previous incomplete snapshots, or even to reuse
// obsolete ones.
func (s *Snapshot) transIncomplete(cl Clock) {
oldName := s.FullName()
s.startTime = cl.Now()
s.endTime = time.Time{}
s.state = STATE_INCOMPLETE
newName := s.FullName()
err := os.Rename(oldName, newName)
if err != nil {
log.Fatal(err)
}
}
// purge deletes the receiver snapshot from disk.
func (s *Snapshot) purge() {
s.transPurging()
......@@ -350,15 +365,3 @@ func LastReusableFromDisk(cl Clock) *Snapshot {
sn := snapshots.state(STATE_INCOMPLETE, NONE).last()
return sn
}
// ReusePartial generates a new incomplete snapshot based on a previous one.
// Can be used to try to use previous incomplete snapshots, or even to reuse
// obsolete ones.
func ReusePartial(orig *Snapshot, cl Clock) *Snapshot {
s := newIncompleteSnapshot(cl)
err := os.Rename(orig.FullName(), s.FullName())
if err != nil {
log.Fatal(err)
}
return s;
}
\ No newline at end of file
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