Reuse temporary files (fixes #4)

This commit is contained in:
Audrius Butkevicius
2014-10-03 23:15:54 +01:00
parent 41b8dd2863
commit 69e385e4cd
6 changed files with 87 additions and 23 deletions

View File

@@ -31,6 +31,7 @@ type sharedPullerState struct {
folder string
tempName string
realName string
reuse bool
// Mutable, must be locked for access
err error // The first error we hit
@@ -77,7 +78,11 @@ func (s *sharedPullerState) tempFile() (*os.File, error) {
}
// Attempt to create the temp file
fd, err := os.OpenFile(s.tempName, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0644)
flags := os.O_WRONLY
if !s.reuse {
flags |= os.O_CREATE | os.O_EXCL
}
fd, err := os.OpenFile(s.tempName, flags, 0644)
if err != nil {
s.earlyCloseLocked("dst create", err)
return nil, err