File: temporal.go

package info (click to toggle)
golang-github-go-git-go-billy 5.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 364 kB
  • sloc: makefile: 10
file content (30 lines) | stat: -rw-r--r-- 725 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package temporal

import (
	"github.com/go-git/go-billy/v5"
	"github.com/go-git/go-billy/v5/util"
)

// Temporal is a helper that implements billy.TempFile over any filesystem.
type Temporal struct {
	billy.Filesystem
	defaultDir string
}

// New creates a new filesystem wrapping up 'fs' the intercepts the calls to
// the TempFile method. The param defaultDir is used as default directory were
// the tempfiles are created.
func New(fs billy.Filesystem, defaultDir string) billy.Filesystem {
	return &Temporal{
		Filesystem: fs,
		defaultDir: defaultDir,
	}
}

func (h *Temporal) TempFile(dir, prefix string) (billy.File, error) {
	if dir == "" {
		dir = h.defaultDir
	}

	return util.TempFile(h.Filesystem, dir, prefix)
}