Skip to content

Commit 2262db3

Browse files
committed
Don't use tempdir
We shouldn't let Afero decide the temporary dir for us, since this could end up on a different filesystem than the repository, and rename() don't work cross filesystems. We don't want to alter .gitignore (which can be edited/managed by someone else or elsewhere), but we can use the local-only .git/info/exclude exclusion file (https://git-scm.com/docs/gitignore). Which allows us to create our temporary files in the repository itself, and keep everything else (even /tmp) read-only.
1 parent 41cd799 commit 2262db3

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

cmd/execute_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestRootCmd(t *testing.T) {
2525
"/dev/null",
2626
"--dry-run",
2727
"--dump-only",
28+
"--no-git",
2829
"--api-server",
2930
"http://192.0.2.1", // RFC 5737 reserved/unroutable
3031
"--log-level",

pkg/recorder/recorder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (w *Listener) save(file string, data []byte) error {
157157
return fmt.Errorf("can't create local directory %s: %v", dir, err)
158158
}
159159

160-
tmpf, err := afero.TempFile(appFs, "", "katafygio")
160+
tmpf, err := afero.TempFile(appFs, dir, ".temp-katafygio-")
161161
if err != nil {
162162
return fmt.Errorf("failed to create a temporary file: %v", err)
163163
}

pkg/store/git/git.go

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ func (s *Store) CloneOrInit() (err error) {
174174
s.Email, s.LocalDir, err)
175175
}
176176

177+
err = afero.WriteFile(appFs, s.LocalDir+"/.git/info/exclude", []byte(".temp-katafygio-*"), 0644)
178+
if err != nil {
179+
return fmt.Errorf("failed to create a git exclusion: %v", err)
180+
}
181+
177182
return nil
178183
}
179184

0 commit comments

Comments
 (0)