From 45d33771c8a40f79511b4f60cdffaf454bf969e5 Mon Sep 17 00:00:00 2001 From: raisons Date: Fri, 3 Nov 2023 11:35:15 +0800 Subject: [PATCH] fix: remove the tempoary theme directory --- service/theme/git_fetcher.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service/theme/git_fetcher.go b/service/theme/git_fetcher.go index 41748cc..c381b36 100644 --- a/service/theme/git_fetcher.go +++ b/service/theme/git_fetcher.go @@ -10,6 +10,7 @@ import ( "go.uber.org/fx" "github.com/go-sonic/sonic/model/dto" + "github.com/go-sonic/sonic/util" "github.com/go-sonic/sonic/util/xerr" ) @@ -25,6 +26,13 @@ func (g gitThemeFetcherImpl) FetchTheme(ctx context.Context, file interface{}) ( tempDir := os.TempDir() themeDirName := lastSplit + tmpThemeDir := filepath.Join(tempDir, themeDirName) + if util.FileIsExisted(tmpThemeDir) { + err := os.RemoveAll(tmpThemeDir) + if err != nil { + return nil, xerr.WithStatus(err, xerr.StatusBadRequest).WithMsg("delete tmp theme directory err") + } + } _, err := git.PlainClone(filepath.Join(tempDir, themeDirName), false, &git.CloneOptions{ URL: gitURL, })