-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Projects controller vs history (#3486)
fixes #3405
- Loading branch information
Vladimir Kotal
authored
Mar 18, 2021
1 parent
36b6a6f
commit 21a91cd
Showing
1 changed file
with
38 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
|
||
/* | ||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. | ||
* Portions Copyright (c) 2020, Chris Fraire <[email protected]>. | ||
*/ | ||
package org.opengrok.web.api.v1.controller; | ||
|
@@ -90,11 +90,13 @@ public Response addProject(String projectName) { | |
if (!env.getProjects().containsKey(projectName)) { | ||
Project project = new Project(projectName, "/" + projectName); | ||
|
||
// Add repositories in this project. | ||
List<RepositoryInfo> repos = getRepositoriesInDir(projDir); | ||
if (env.isHistoryEnabled()) { | ||
// Add repositories in this project. | ||
List<RepositoryInfo> repos = getRepositoriesInDir(projDir); | ||
|
||
env.addRepositories(repos); | ||
env.getProjectRepositoriesMap().put(project, repos); | ||
env.addRepositories(repos); | ||
env.getProjectRepositoriesMap().put(project, repos); | ||
} | ||
|
||
// Finally introduce the project to the configuration. | ||
// Note that the project is inactive in the UI until it is indexed. | ||
|
@@ -105,29 +107,31 @@ public Response addProject(String projectName) { | |
Project project = env.getProjects().get(projectName); | ||
Map<Project, List<RepositoryInfo>> map = env.getProjectRepositoriesMap(); | ||
|
||
// Refresh the list of repositories of this project. | ||
// This is the goal of this action: if an existing project | ||
// is re-added, this means its list of repositories has changed. | ||
List<RepositoryInfo> repos = getRepositoriesInDir(projDir); | ||
List<RepositoryInfo> allrepos = env.getRepositories(); | ||
synchronized (allrepos) { | ||
// newly added repository | ||
for (RepositoryInfo repo : repos) { | ||
if (!allrepos.contains(repo)) { | ||
allrepos.add(repo); | ||
if (env.isHistoryEnabled()) { | ||
// Refresh the list of repositories of this project. | ||
// This is the goal of this action: if an existing project | ||
// is re-added, this means its list of repositories has changed. | ||
List<RepositoryInfo> repos = getRepositoriesInDir(projDir); | ||
List<RepositoryInfo> allrepos = env.getRepositories(); | ||
synchronized (allrepos) { | ||
// newly added repository | ||
for (RepositoryInfo repo : repos) { | ||
if (!allrepos.contains(repo)) { | ||
allrepos.add(repo); | ||
} | ||
} | ||
} | ||
// deleted repository | ||
if (map.containsKey(project)) { | ||
for (RepositoryInfo repo : map.get(project)) { | ||
if (!repos.contains(repo)) { | ||
allrepos.remove(repo); | ||
// deleted repository | ||
if (map.containsKey(project)) { | ||
for (RepositoryInfo repo : map.get(project)) { | ||
if (!repos.contains(repo)) { | ||
allrepos.remove(repo); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
map.put(project, repos); | ||
map.put(project, repos); | ||
} | ||
} | ||
|
||
return Response.status(Response.Status.CREATED).build(); | ||
|
@@ -174,12 +178,14 @@ public void deleteProject(@PathParam("project") String projectName) | |
group.getProjects().remove(project); | ||
} | ||
|
||
// Now remove the repositories associated with this project. | ||
List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(project); | ||
if (repos != null) { | ||
env.getRepositories().removeAll(repos); | ||
if (env.isHistoryEnabled()) { | ||
// Now remove the repositories associated with this project. | ||
List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(project); | ||
if (repos != null) { | ||
env.getRepositories().removeAll(repos); | ||
} | ||
env.getProjectRepositoriesMap().remove(project); | ||
} | ||
env.getProjectRepositoriesMap().remove(project); | ||
|
||
env.getProjects().remove(projectName, project); | ||
|
||
|
@@ -215,6 +221,10 @@ public void deleteProjectData(@PathParam("project") String projectNameParam) { | |
@DELETE | ||
@Path("/{project}/historycache") | ||
public void deleteHistoryCache(@PathParam("project") String projectName) { | ||
if (!env.isHistoryEnabled()) { | ||
return; | ||
} | ||
|
||
// Avoid classification as a taint bug. | ||
projectName = Laundromat.launderInput(projectName); | ||
|
||
|