keon94 commented on code in PR #2050:
URL: https://github.com/apache/incubator-devlake/pull/2050#discussion_r897464405


##########
plugins/gitextractor/parser/clone.go:
##########
@@ -64,29 +71,46 @@ func (l *LibGit2) CloneOverHTTP(repoId, url, user, 
password, proxy string) error
        }
        dir, err := ioutil.TempDir("", "gitextractor")
        if err != nil {
-               return err
+               return nil, err
+       }
+       cleanup = func() {
+               os.RemoveAll(dir)
        }
-       defer os.RemoveAll(dir)
-       repo, err := git.Clone(url, dir, cloneOptions)
+       clonedRepo, err := git.Clone(url, dir, cloneOptions)
        if err != nil {
-               return err
+               return nil, err
        }
-       return l.run(repo, repoId)
+       repo = l.newGitRepo(repoId, clonedRepo, cleanup)
+       return repo, err
 }
 
-func (l *LibGit2) CloneOverSSH(repoId, url, privateKey, passphrase string) 
error {
+func (l *GitRepoCreator) CloneOverSSH(repoId, url, privateKey, passphrase 
string) (*GitRepo, error) {
+       var cleanup func()
+       var repo *GitRepo
+       defer func() {
+               if repo == nil {
+                       cleanup()
+               }
+       }()
        dir, err := ioutil.TempDir("", "gitextractor")
        if err != nil {
-               return err
+               return nil, err

Review Comment:
   I went with wrapping the whole temp directory logic in a function to keep 
the clone functions clean. Let me know what you think



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to