mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-08-06 22:33:07 +02:00
Fix temp dir permission problem on multi-user machines (#4796)
In 3a9dbf7341
we created a global /tmp/lazygit/ folder that contains
the temp directories of each running instance, to avoid polluting /tmp
with multiple folders. The problem with that approach was that the
folder was created with 700 permissions, so if multiple users were using
lazygit on the same machine (e.g. a server), all users except the first
one would get fatal errors on startup.
Fix this by creating temp folders containing the user's uid.
Fixes #4793.
This commit is contained in:
@ -8,6 +8,7 @@ import (
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
@ -124,11 +125,7 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
tmpDirBase := filepath.Join(os.TempDir(), "lazygit")
|
||||
if err := os.MkdirAll(tmpDirBase, 0o700); err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
tempDir, err := os.MkdirTemp(tmpDirBase, "")
|
||||
tempDir, err := os.MkdirTemp(getTempDirBase(), "lazygit-*")
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
@ -314,3 +311,19 @@ func getGitVersionInfo() string {
|
||||
gitVersion := strings.Trim(strings.TrimPrefix(string(stdout), "git version "), " \r\n")
|
||||
return gitVersion
|
||||
}
|
||||
|
||||
func getTempDirBase() string {
|
||||
tempDir := os.TempDir()
|
||||
|
||||
user, err := user.Current()
|
||||
if err != nil || user.Uid == "" {
|
||||
return tempDir
|
||||
}
|
||||
|
||||
tmpDirBase := filepath.Join(tempDir, "lazygit-"+user.Uid)
|
||||
if err := os.MkdirAll(tmpDirBase, 0o700); err != nil {
|
||||
return tempDir
|
||||
}
|
||||
|
||||
return tmpDirBase
|
||||
}
|
||||
|
Reference in New Issue
Block a user