Skip to content

Commit

Permalink
add: temp directory and file cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Souvik Kar Mahapatra <souvikat001@gmail.com>
  • Loading branch information
souvikinator committed Jan 24, 2025
1 parent 785a2df commit 7d3da8f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions generators/github/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@ func (gr GitRepo) GetContent() (models.Package, error) {
dirPath := filepath.Join(os.TempDir(), owner, repo, branch)
_ = os.MkdirAll(dirPath, 0755)
filePath := filepath.Join(dirPath, utils.GetRandomAlphabetsOfDigit(5))
fd, err := os.Create(filePath) // perform cleanup
fd, err := os.Create(filePath)
if err != nil {
os.RemoveAll(dirPath)
return nil, utils.ErrCreateFile(err, filePath)
}
br := bufio.NewWriter(fd)

defer func() {
_ = br.Flush()
br.Flush()
fd.Close()
os.Remove(filePath)
os.RemoveAll(dirPath)
}()
gw := gitWalker.
Owner(owner).
Expand Down

0 comments on commit 7d3da8f

Please sign in to comment.