diff --git a/api/projects/repository.go b/api/projects/repository.go index 08dedd0a..98104658 100644 --- a/api/projects/repository.go +++ b/api/projects/repository.go @@ -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,