From 21b7c3cd71c0af4470fd5135df4b798224f92d9b Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sun, 17 Jun 2007 23:00:16 +0000 Subject: [PATCH] fixed #585 "Hudson follows symlinks when deleting" git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@3474 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/Util.java | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index 987a0832cd..28076edfdc 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. */ -- GitLab