Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projects controller vs history #3486

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down