diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 987a0832cd2bd2ec92f1d6019a543248c4cd8e8a..28076edfdc9df656ce4cdb000fe6c4d8df65bb14 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -143,10 +143,40 @@ public class Util { } public static void deleteRecursive(File dir) throws IOException { - deleteContentsRecursive(dir); + if(!isSymlink(dir)) + deleteContentsRecursive(dir); deleteFile(dir); } + /* + * Copyright 2001-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /** + * Checks if the given file represents a symlink. + */ + //Taken from http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?view=markup + public boolean isSymlink(File file) throws IOException { + File parent = file.getParentFile(); + File canonicalFile = file.getCanonicalFile(); + + return parent != null + && (!canonicalFile.getName().equals(file.getName()) || !canonicalFile.getPath().startsWith( + parent.getCanonicalPath())); + } + + /** * Creates a new temporary directory. */