mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-11-23 20:35:24 +01:00
Clear repository cache after update/delete repository information.
Close #159
This commit is contained in:
parent
e312f272e2
commit
0d33a7df5e
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user