aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-10-19 12:44:17 +0200
committerGitHub <noreply@github.com>2016-10-19 12:44:17 +0200
commit7bd4f1d2b796de5c86466b40eaa561d4fd27931b (patch)
tree8699f5ff6df8cb3fbdf8d2b9df0adf975c60d542 /storage/filesystem
parentc56b22fc73d0ca3c4d44872e8b16370e041dcd92 (diff)
downloadgo-git-7bd4f1d2b796de5c86466b40eaa561d4fd27931b.tar.gz
utils: fs.TempFile (#88)
* utils: fs generic TestSuite * fs: fs.TempFile * utils: fs small changes requested * utils: fs, test fs.Create overwriting files
Diffstat (limited to 'storage/filesystem')
-rw-r--r--storage/filesystem/internal/dotgit/writers.go14
1 files changed, 3 insertions, 11 deletions
diff --git a/storage/filesystem/internal/dotgit/writers.go b/storage/filesystem/internal/dotgit/writers.go
index 40b004f..4641572 100644
--- a/storage/filesystem/internal/dotgit/writers.go
+++ b/storage/filesystem/internal/dotgit/writers.go
@@ -1,11 +1,9 @@
package dotgit
import (
- "crypto/sha1"
"fmt"
"io"
"sync/atomic"
- "time"
"gopkg.in/src-d/go-git.v4/core"
"gopkg.in/src-d/go-git.v4/formats/idxfile"
@@ -26,15 +24,12 @@ type PackWriter struct {
}
func newPackWrite(fs fs.Filesystem) (*PackWriter, error) {
- seed := sha1.Sum([]byte(time.Now().String()))
- tmp := fs.Join(objectsPath, packPath, fmt.Sprintf("tmp_pack_%x", seed))
-
- fw, err := fs.Create(tmp)
+ fw, err := fs.TempFile(fs.Join(objectsPath, packPath), "tmp_pack_")
if err != nil {
return nil, err
}
- fr, err := fs.Open(tmp)
+ fr, err := fs.Open(fw.Filename())
if err != nil {
return nil, err
}
@@ -228,10 +223,7 @@ type ObjectWriter struct {
}
func newObjectWriter(fs fs.Filesystem) (*ObjectWriter, error) {
- seed := sha1.Sum([]byte(time.Now().String()))
- tmp := fs.Join(objectsPath, fmt.Sprintf("tmp_obj_%x", seed))
-
- f, err := fs.Create(tmp)
+ f, err := fs.TempFile(fs.Join(objectsPath, packPath), "tmp_obj_")
if err != nil {
return nil, err
}