Skip to content

Commit f65c523

Browse files
authored
Remove temp clone dir after writing a repository (knative#4053)
Repository.Write clones remote repos into a directory from os.MkdirTemp and copies it to the destination, but never removed the directory. Every 'func repository add' left a full clone under the system temp dir. Defer os.RemoveAll so the clone is removed on both success and failure.
1 parent 7273bc4 commit f65c523

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

‎pkg/functions/repository.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ func (r *Repository) Write(dest string) (err error) {
714714
if tempDir, err = os.MkdirTemp("", "func"); err != nil {
715715
return
716716
}
717+
defer os.RemoveAll(tempDir)
717718
cloneOpts := getGitCloneOptions(r.uri)
718719
_, err = git.PlainClone(tempDir, false, cloneOpts) // not bare
719720
if isAuthError(err) {

0 commit comments

Comments
 (0)