media: use cache directory for temp files

This commit is contained in:
Tulir Asokan 2024-10-11 20:09:51 +03:00
parent 420a7dab4e
commit 704fe45eb9
2 changed files with 6 additions and 1 deletions

View file

@ -53,6 +53,7 @@ type Gomuks struct {
ConfigDir string
DataDir string
CacheDir string
TempDir string
LogDir string
stopOnce sync.Once
@ -133,8 +134,12 @@ func (gmx *Gomuks) LoadConfig() {
gmx.LogDir = filepath.Join(homeDir, ".local", "state", "gomuks")
}
}
if gmx.TempDir = os.Getenv("GOMUKS_TMPDIR"); gmx.TempDir == "" {
gmx.TempDir = filepath.Join(gmx.CacheDir, "tmp")
}
exerrors.PanicIfNotNil(os.MkdirAll(gmx.ConfigDir, 0700))
exerrors.PanicIfNotNil(os.MkdirAll(gmx.CacheDir, 0700))
exerrors.PanicIfNotNil(os.MkdirAll(gmx.TempDir, 0700))
exerrors.PanicIfNotNil(os.MkdirAll(gmx.DataDir, 0700))
exerrors.PanicIfNotNil(os.MkdirAll(gmx.LogDir, 0700))
}

View file

@ -106,7 +106,7 @@ func (gmx *Gomuks) DownloadMedia(w http.ResponseWriter, r *http.Request) {
return
}
tempFile, err := os.CreateTemp("", "gomuks-download-*")
tempFile, err := os.CreateTemp(gmx.TempDir, "download-*")
if err != nil {
log.Err(err).Msg("Failed to create temporary file")
mautrix.MUnknown.WithMessage(fmt.Sprintf("Failed to create temp file: %v", err)).Write(w)