@@ -3,19 +3,21 @@ package fixtures
33import (
44 "fmt"
55 "io"
6- "io/ioutil"
76 "os"
87 "strings"
98
10- "github.com/alcortesm/tgz"
119 "github.com/go-git/go-billy/v5"
1210 "github.com/go-git/go-billy/v5/osfs"
11+ "github.com/go-git/go-git-fixtures/v4/internal/tgz"
1312 "gopkg.in/check.v1"
1413)
1514
1615//go:generate esc -o data.go -pkg=fixtures data
1716
18- var files = make (map [string ]string )
17+ var (
18+ files = make (map [string ]string )
19+ fs = osfs .New (os .TempDir ())
20+ )
1921
2022var fixtures = Fixtures {{
2123 Tags : []string {"packfile" , "ofs-delta" , ".git" , "root-reference" },
@@ -203,17 +205,17 @@ func (f *Fixture) Is(tag string) bool {
203205 return false
204206}
205207
206- func (f * Fixture ) file (path string ) (* os .File , error ) {
208+ func (f * Fixture ) file (path string ) (billy .File , error ) {
207209 if fpath , ok := files [path ]; ok {
208- return os .Open (fpath )
210+ return fs .Open (fpath )
209211 }
210212
211213 bytes , err := FSByte (false , "/data/" + path )
212214 if err != nil {
213215 return nil , err
214216 }
215217
216- file , err := ioutil .TempFile (os . TempDir () , "go-git-fixtures" )
218+ file , err := fs .TempFile ("" , "go-git-fixtures" )
217219 if err != nil {
218220 return nil , err
219221 }
@@ -222,32 +224,29 @@ func (f *Fixture) file(path string) (*os.File, error) {
222224 return nil , err
223225 }
224226
225- if err := file .Sync (); err != nil {
226- return nil , err
227- }
228-
229- if _ , err := file .Seek (0 , io .SeekStart ); err != nil {
227+ if err := file .Close (); err != nil {
230228 return nil , err
231229 }
232230
233231 files [path ] = file .Name ()
234-
235- return file , nil
232+ return fs .Open (file .Name ())
236233}
237234
238- func (f * Fixture ) Packfile () * os .File {
235+ func (f * Fixture ) Packfile () billy .File {
239236 file , err := f .file (fmt .Sprintf ("pack-%s.pack" , f .PackfileHash ))
240237 if err != nil {
241238 panic (err )
242239 }
240+
243241 return file
244242}
245243
246- func (f * Fixture ) Idx () * os .File {
244+ func (f * Fixture ) Idx () billy .File {
247245 file , err := f .file (fmt .Sprintf ("pack-%s.idx" , f .PackfileHash ))
248246 if err != nil {
249247 panic (err )
250248 }
249+
251250 return file
252251}
253252
@@ -264,12 +263,12 @@ func (f *Fixture) DotGit() billy.Filesystem {
264263 panic (err )
265264 }
266265
267- path , err := tgz .Extract (file .Name ())
266+ fs , err := tgz .Extract (fs , file .Name ())
268267 if err != nil {
269268 panic (err )
270269 }
271270
272- return osfs . New ( path )
271+ return fs
273272}
274273
275274// EnsureIsBare overrides the config file with one where bare is true.
@@ -304,12 +303,12 @@ func (f *Fixture) Worktree() billy.Filesystem {
304303 panic (err )
305304 }
306305
307- path , err := tgz .Extract (file .Name ())
306+ fs , err := tgz .Extract (fs , file .Name ())
308307 if err != nil {
309308 panic (err )
310309 }
311310
312- return osfs . New ( path )
311+ return fs
313312}
314313
315314type Fixtures []* Fixture
@@ -360,7 +359,7 @@ func (g Fixtures) Exclude(tag string) Fixtures {
360359// Clean cleans all the temporal files created
361360func Clean () error {
362361 for fname , f := range files {
363- if err := os .Remove (f ); err != nil {
362+ if err := fs .Remove (f ); err != nil {
364363 return err
365364 }
366365 delete (files , fname )
0 commit comments