mirror of
https://github.com/restic/restic.git
synced 2026-06-21 16:14:18 +00:00
4d1b9cef63
Move TempFile and PreallocateFile into internal/fileio. internal/fs primarily focuses on converting between data.Node and the actual filesystem state. Extract the two methods to not pull in unnecessary dependencies.
23 lines
370 B
Go
23 lines
370 B
Go
//go:build !windows
|
|
|
|
package fileio
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// TempFile creates a temporary file which has already been deleted (on
|
|
// supported platforms)
|
|
func TempFile(dir, prefix string) (f *os.File, err error) {
|
|
f, err = os.CreateTemp(dir, prefix)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if err = os.Remove(f.Name()); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return f, nil
|
|
}
|