Browse Source

Remove orphaned temp files before attempting to remove directories (fixes #492)

Jakob Borg 11 years ago
parent
commit
0a70e0b7b6
1 changed files with 8 additions and 2 deletions
  1. 8 2
      model/puller.go

+ 8 - 2
model/puller.go

@@ -222,7 +222,7 @@ func (p *puller) run() {
 
 		if changed {
 			p.model.setState(p.repoCfg.ID, RepoCleaning)
-			p.fixupDirectories()
+			p.clean()
 			changed = false
 		}
 
@@ -261,7 +261,9 @@ func (p *puller) runRO() {
 	}
 }
 
-func (p *puller) fixupDirectories() {
+// clean deletes orphaned temporary files and directories that should no
+// longer exist.
+func (p *puller) clean() {
 	var deleteDirs []string
 	var changed = 0
 
@@ -270,6 +272,10 @@ func (p *puller) fixupDirectories() {
 			return err
 		}
 
+		if info.Mode().IsRegular() && defTempNamer.IsTemporary(path) {
+			os.Remove(path)
+		}
+
 		if !info.IsDir() {
 			return nil
 		}