You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/09/03 20:30:44 UTC
svn commit: r691718 - in /maven/shared/trunk/file-management/src:
main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
Author: bentmann
Date: Wed Sep 3 11:30:43 2008
New Revision: 691718
URL: http://svn.apache.org/viewvc?rev=691718&view=rev
Log:
[MSHARED-57] FileSetManager.isSymlink() produces false negatives
o Fixed symlink detection as inspired by FileUtils.isSymlink() from Commons IO 2.0
Modified:
maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
Modified: maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java?rev=691718&r1=691717&r2=691718&view=diff
==============================================================================
--- maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java (original)
+++ maven/shared/trunk/file-management/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java Wed Sep 3 11:30:43 2008
@@ -371,17 +371,25 @@
private boolean isSymlink( File file )
throws IOException
{
- File parent = file.getParentFile();
- File canonicalFile = file.getCanonicalFile();
-
+ File fileInCanonicalParent = null;
+ File parentDir = file.getParentFile();
+ if ( parentDir == null )
+ {
+ fileInCanonicalParent = file;
+ }
+ else
+ {
+ fileInCanonicalParent = new File( parentDir.getCanonicalPath(), file.getName() );
+ }
if ( messages != null && messages.isDebugEnabled() )
{
- messages.addDebugMessage( "Checking for symlink:\nParent file's canonical path: "
- + parent.getCanonicalPath() + "\nMy canonical path: " + canonicalFile.getPath() ).flush();
+ messages.addDebugMessage(
+ "Checking for symlink:\nFile's canonical path: "
+ + fileInCanonicalParent.getCanonicalPath()
+ + "\nFile's absolute path with canonical parent: "
+ + fileInCanonicalParent.getPath() ).flush();
}
- return parent != null
- && ( !canonicalFile.getName().equals( file.getName() ) || !canonicalFile.getPath()
- .startsWith( parent.getCanonicalPath() ) );
+ return !fileInCanonicalParent.getCanonicalFile().equals( fileInCanonicalParent.getAbsoluteFile() );
}
private Set findDeletablePaths( FileSet fileSet )
Modified: maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java?rev=691718&r1=691717&r2=691718&view=diff
==============================================================================
--- maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java (original)
+++ maven/shared/trunk/file-management/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java Wed Sep 3 11:30:43 2008
@@ -94,7 +94,7 @@
throws IOException, InterruptedException, CommandLineException
{
File directory = setupTestDirectory( "testIncludesDontFollowSymlinks" );
- File subdir = new File( directory, "linked-to-self" );
+ File subdir = new File( directory, directory.getName() );
if ( !createSymlink( directory, subdir ) )
{
@@ -124,7 +124,7 @@
throws IOException, InterruptedException, CommandLineException
{
File directory = setupTestDirectory( "testDeleteDontFollowSymlinks" );
- File subdir = new File( directory, "linked-to-self" );
+ File subdir = new File( directory, directory.getName() );
if ( !createSymlink( directory, subdir ) )
{
@@ -136,7 +136,7 @@
FileSet set = new FileSet();
set.setDirectory( directory.getPath() );
set.addInclude( "**/included.txt" );
- set.addInclude( "**/linked-to-self" );
+ set.addInclude( "**/" + subdir.getName() );
set.setFollowSymlinks( false );
FileSetManager fileSetManager = new FileSetManager();