diff options
author | zeripath <art27@cantab.net> | 2019-11-13 07:01:19 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-13 07:01:19 +0000 |
commit | 722a7c902dd39bd3d4328345ca969220640774d7 (patch) | |
tree | 7fb83b70fd9df55fd7d3a805adf38238d6a9bca8 /routers/repo/setting.go | |
parent | 7b97e045557788efee6803261cf612eaf975c6be (diff) | |
download | gitea-722a7c902dd39bd3d4328345ca969220640774d7.tar.gz gitea-722a7c902dd39bd3d4328345ca969220640774d7.zip |
Add Close() method to gogitRepository (#8901)
In investigating #7947 it has become clear that the storage component of go-git repositories needs closing.
This PR adds this Close function and adds the Close functions as necessary.
In TransferOwnership the ctx.Repo.GitRepo is closed if it is open to help prevent the risk of multiple open files.
Fixes #7947
Diffstat (limited to 'routers/repo/setting.go')
-rw-r--r-- | routers/repo/setting.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/routers/repo/setting.go b/routers/repo/setting.go index f699c1d685..fa215357d2 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -73,6 +73,11 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { // Check if repository name has been changed. if repo.LowerName != strings.ToLower(newRepoName) { isNameChanged = true + // Close the GitRepo if open + if ctx.Repo.GitRepo != nil { + ctx.Repo.GitRepo.Close() + ctx.Repo.GitRepo = nil + } if err := models.ChangeRepositoryName(ctx.Repo.Owner, repo.Name, newRepoName); err != nil { ctx.Data["Err_RepoName"] = true switch { @@ -379,6 +384,11 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { } oldOwnerID := ctx.Repo.Owner.ID + // Close the GitRepo if open + if ctx.Repo.GitRepo != nil { + ctx.Repo.GitRepo.Close() + ctx.Repo.GitRepo = nil + } if err = models.TransferOwnership(ctx.User, newOwner, repo); err != nil { if models.IsErrRepoAlreadyExist(err) { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil) |