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


##########
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:
   The only issue with that is, the GitRepo object won't be initialized so we 
can't call Close() on it. I can work around that too, but that'll also add 
complexity. I'll try to clean the code up here to make it easier to follow



-- 
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