git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@935069 13f79535-47bb-0310-9956-ffa450edef68master
@@ -64,7 +64,7 @@ public class SymbolicLinkUtils { | |||||
* canonical and absolute paths of the file are identical--this | * canonical and absolute paths of the file are identical--this | ||||
* may lead to false positives on some platforms.</p> | * may lead to false positives on some platforms.</p> | ||||
* | * | ||||
* @param file the file to test. | |||||
* @param file the file to test. Must not be null. | |||||
* | * | ||||
* @return true if the file is a symbolic link. | * @return true if the file is a symbolic link. | ||||
* @throws IOException on error. | * @throws IOException on error. | ||||
@@ -104,7 +104,9 @@ public class SymbolicLinkUtils { | |||||
*/ | */ | ||||
public boolean isSymbolicLink(File parent, String name) | public boolean isSymbolicLink(File parent, String name) | ||||
throws IOException { | throws IOException { | ||||
File toTest = new File(parent.getCanonicalPath(), name); | |||||
File toTest = parent != null | |||||
? new File(parent.getCanonicalPath(), name) | |||||
: new File(name); | |||||
return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath()); | return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath()); | ||||
} | } | ||||
@@ -0,0 +1,33 @@ | |||||
/* | |||||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||||
* contributor license agreements. See the NOTICE file distributed with | |||||
* this work for additional information regarding copyright ownership. | |||||
* The ASF licenses this file to You 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. | |||||
* | |||||
*/ | |||||
package org.apache.tools.ant.util; | |||||
import java.io.IOException; | |||||
import junit.framework.TestCase; | |||||
public class SymlinkUtilsTest extends TestCase { | |||||
private static final SymbolicLinkUtils SYMLINK_UTILS = | |||||
SymbolicLinkUtils.getSymbolicLinkUtils(); | |||||
public void testRootIsNoSymlink() throws IOException { | |||||
assertFalse(SYMLINK_UTILS.isSymbolicLink("/")); | |||||
} | |||||
} |