Skip to content

Commit 47afa7e

Browse files
authored
Improve temp dir handling (#4784)
- Lazygit creates a temp dir at startup, and is supposed to clean it up after itself; however, this only worked for the main executable, not when lazygit was spawned as a helper daemon for interactive rebases, so we would leak a temp dir every time the user pressed `e` or `ctrl-j` or other similar commands. - All these temp dirs were created at top level in `/tmp` and thus pollute it; now we create them inside a `/tmp/lazygit/` folder. This is no longer quite as important now that the first bug is fixed, but might still be useful when lazygit crashes, or when running many instances at once in different terminal tabs. Resolves #4781.
2 parents 05c30b8 + 3a9dbf7 commit 47afa7e

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test/git_server/data
2222
test/_results/**
2323

2424
oryxBuildBinary
25-
__debug_bin
25+
__debug_bin*
2626

2727
.worktrees
2828
demo/output/*

pkg/app/daemon/daemon.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,6 @@ func Handle(common *common.Common) {
7676
if err := instruction.run(common); err != nil {
7777
log.Fatal(err)
7878
}
79-
80-
os.Exit(0)
8179
}
8280

8381
func InDaemonMode() bool {

pkg/app/entry_point.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ func Start(buildInfo *BuildInfo, integrationTest integrationTypes.IntegrationTes
124124
os.Exit(0)
125125
}
126126

127-
tempDir, err := os.MkdirTemp("", "lazygit-*")
127+
tmpDirBase := filepath.Join(os.TempDir(), "lazygit")
128+
if err := os.MkdirAll(tmpDirBase, 0o700); err != nil {
129+
log.Fatal(err.Error())
130+
}
131+
tempDir, err := os.MkdirTemp(tmpDirBase, "")
128132
if err != nil {
129133
log.Fatal(err.Error())
130134
}

0 commit comments

Comments
 (0)