Skip to content

Commit

Permalink
Possible fix for JENKINS-9806, fix empty customWorkspace -if empry, r…
Browse files Browse the repository at this point in the history
…eplace it by null (i.e. no custom workspace)
  • Loading branch information
vjuranek authored and kohsuke committed Jun 7, 2011
1 parent 9d89b9f commit 8b4f30a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions core/src/main/java/hudson/model/AbstractProject.java
Expand Up @@ -1655,7 +1655,7 @@ protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOExceptio
blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null;

if(req.hasParameter("customWorkspace")) {
customWorkspace = req.getParameter("customWorkspace.directory");
customWorkspace = fixEmpty(req.getParameter("customWorkspace.directory"));
} else {
customWorkspace = null;
}
Expand Down Expand Up @@ -1995,7 +1995,23 @@ public String getCustomWorkspace() {
* @since 1.410
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
this.customWorkspace= customWorkspace;
this.customWorkspace= fixEmpty(customWorkspace);
save();
}

/**
* Replace customWorkspace by null if customWorkspace is empty string. This should prevent user to
* delete JENKIS_HOME accidentally, see JENKINS-9806 for details. If user wants to set up
* JENKINS_HOME as a workspace for some reason, he can use "." to do so.
*
* @param customWorkspace
* @return customWorkspace if it's not empty string, null otherwise
*/
private String fixEmpty(String customWorkspace){
if(customWorkspace!=null && customWorkspace.trim().equals("")){
return null;
}
return customWorkspace;
}

}

0 comments on commit 8b4f30a

Please sign in to comment.