Clear repository cache after update/delete repository information.

Close #159
This commit is contained in:
Tokuhiro Matsuno 2016-06-30 19:54:09 -04:00
parent e312f272e2
commit 0d33a7df5e

View File

@ -2,6 +2,8 @@ package projects
import (
"database/sql"
"os"
"strconv"
database "github.com/ansible-semaphore/semaphore/db"
"github.com/ansible-semaphore/semaphore/models"
@ -10,6 +12,16 @@ import (
"github.com/masterminds/squirrel"
)
func clearRepositoryCache(repository models.Repository) error {
repoName := "repository_" + strconv.Itoa(repository.ID)
repoPath := util.Config.TmpPath + "/" + repoName
_, err := os.Stat(repoPath)
if err == nil {
return os.RemoveAll(repoPath)
}
return nil
}
func RepositoryMiddleware(c *gin.Context) {
project := c.MustGet("project").(models.Project)
repositoryID, err := util.GetIntParam("repository_id", c)
@ -97,6 +109,10 @@ func UpdateRepository(c *gin.Context) {
panic(err)
}
if oldRepo.GitUrl != repository.GitUrl {
clearRepositoryCache(oldRepo)
}
desc := "Repository (" + repository.GitUrl + ") updated"
objType := "inventory"
if err := (models.Event{
@ -141,6 +157,8 @@ func RemoveRepository(c *gin.Context) {
panic(err)
}
clearRepositoryCache(repository)
desc := "Repository (" + repository.GitUrl + ") deleted"
if err := (models.Event{
ProjectID: &repository.ProjectID,