Browse Source

Merge pull request #853 from AudriusButkevicius/unfinished

Keep temporaries for reuse, cleanup before pull (fixes #849, fixes #841)
Jakob Borg 11 years ago
parent
commit
d4079a3273
1 changed files with 3 additions and 9 deletions
  1. 3 9
      internal/model/puller.go

+ 3 - 9
internal/model/puller.go

@@ -94,9 +94,6 @@ func (p *Puller) Serve() {
 
 	var prevVer uint64
 
-	// Clean out old temporaries before we start pulling
-	p.clean()
-
 	// We don't start pulling files until a scan has been completed.
 	initialScanCompleted := false
 
@@ -131,6 +128,9 @@ loop:
 				continue
 			}
 
+			// Clean out old temporaries before we start pulling
+			p.clean()
+
 			if debug {
 				l.Debugln(p, "pulling", prevVer, curVer)
 			}
@@ -649,14 +649,12 @@ func (p *Puller) finisherRoutine(in <-chan *sharedPullerState) {
 			// Verify the file against expected hashes
 			fd, err := os.Open(state.tempName)
 			if err != nil {
-				os.Remove(state.tempName)
 				l.Warnln("puller: final:", err)
 				continue
 			}
 			err = scanner.Verify(fd, protocol.BlockSize, state.file.Blocks)
 			fd.Close()
 			if err != nil {
-				os.Remove(state.tempName)
 				l.Warnln("puller: final:", state.file.Name, err)
 				continue
 			}
@@ -665,7 +663,6 @@ func (p *Puller) finisherRoutine(in <-chan *sharedPullerState) {
 			if !p.ignorePerms {
 				err = os.Chmod(state.tempName, os.FileMode(state.file.Flags&0777))
 				if err != nil {
-					os.Remove(state.tempName)
 					l.Warnln("puller: final:", err)
 					continue
 				}
@@ -682,7 +679,6 @@ func (p *Puller) finisherRoutine(in <-chan *sharedPullerState) {
 					// sync.
 					l.Infof("Puller (folder %q, file %q): final: %v (continuing anyway as requested)", p.folder, state.file.Name, err)
 				} else {
-					os.Remove(state.tempName)
 					l.Warnln("puller: final:", err)
 					continue
 				}
@@ -694,7 +690,6 @@ func (p *Puller) finisherRoutine(in <-chan *sharedPullerState) {
 			if p.versioner != nil {
 				err = p.versioner.Archive(state.realName)
 				if err != nil {
-					os.Remove(state.tempName)
 					l.Warnln("puller: final:", err)
 					continue
 				}
@@ -703,7 +698,6 @@ func (p *Puller) finisherRoutine(in <-chan *sharedPullerState) {
 			// Replace the original file with the new one
 			err = osutil.Rename(state.tempName, state.realName)
 			if err != nil {
-				os.Remove(state.tempName)
 				l.Warnln("puller: final:", err)
 				continue
 			}