mirror of
https://git.freecumextremist.com/grumbulon/pomme.git
synced 2024-11-16 22:44:13 +00:00
32 lines
711 B
Go
32 lines
711 B
Go
package util
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func MakeLocal(filename, username string, buf bytes.Buffer) error {
|
|
defer buf.Reset()
|
|
|
|
f, err := os.Create("/tmp/tmpfile-" + filename + "-" + username) //nolint: gosec
|
|
// this is set to nolint because I am doing everything os.CreateTemp does but here since I don't like some of the limitations
|
|
if err != nil {
|
|
return fmt.Errorf("failed to write file locally: %w", err)
|
|
}
|
|
|
|
// close and remove the temporary file at the end of the program
|
|
defer func() {
|
|
if err = f.Close(); err != nil {
|
|
return
|
|
}
|
|
}()
|
|
|
|
err = os.WriteFile(f.Name(), buf.Bytes(), 0o600)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to write file locally: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|