aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-07-18 23:25:08 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-07-18 23:25:08 +0200
commit34d8d19bc7e5f1051bd09d9daa687c8f08eace6d (patch)
tree0072dc6cd79b05bba963d6a575c96165f5958065 /storage/filesystem
parentb22e7fa5a7bcd5492aaf9ec11f57cb4322eb8cb4 (diff)
downloadgo-git-34d8d19bc7e5f1051bd09d9daa687c8f08eace6d.tar.gz
storage: dotgit, close temp file before rename
Diffstat (limited to 'storage/filesystem')
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index f3a2308..7950af9 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -348,7 +348,6 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e
return err
}
- defer ioutil.CheckClose(f, &err)
// Creating the temp file in the same directory as the target file
// improves our chances for rename operation to be atomic.
@@ -357,10 +356,6 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e
return err
}
- tmpPath := tmp.Name()
- defer ioutil.CheckClose(tmp, &err)
- defer d.fs.Remove(tmpPath)
-
s := bufio.NewScanner(f)
found := false
for s.Scan() {
@@ -388,7 +383,15 @@ func (d *DotGit) rewritePackedRefsWithoutRef(name plumbing.ReferenceName) (err e
return nil
}
- return d.fs.Rename(tmpPath, packedRefsPath)
+ if err := f.Close(); err != nil {
+ return err
+ }
+
+ if err := tmp.Close(); err != nil {
+ return err
+ }
+
+ return d.fs.Rename(tmp.Name(), packedRefsPath)
}
// process lines from a packed-refs file