You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Kristian Rosenvold <kr...@gmail.com> on 2014/11/15 17:01:26 UTC

Copy with proper symlink behaviour

plexus-utils 3.0.21 now supports full symlink support in the "copy"
operation. It was a bit hard to retain *exact* call compatibility, and
the following code is required:

DirectoryScanner scanner = new DirectoryScanner();
scanner.setBasedir( sourceDir );
scanner.scan();
// Create all the directories, including any symlinks present in source
FileUtils.mkDirs( sourceDir, scanner.getIncludedDirectories(), destDir );

for ( String includedFile : scanner.getIncludedFiles() )
{
    File sourceFile = new File( sourceDir, includedFile );
    File destFile = new File( destDir, includedFile );
    FileUtils.copyFile( sourceFile, destFile );
}


The "clue" here is the call to "FileUtils.mkdirs", which will
effectively recreate any directory symlinks in the source directory.
FileUtils.copyFile will copy *file* symlinks.

There is a fair amount of code in out codebase that has logic like
"createParentDirectories" which will always assume that a parent
directory is a directory. Using FileUtils.mkdirs will read the source
structure and create the appropriate kind of target element

This will be release for m-s-u "soon" too :)

Kristian

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org