Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#130 DirectoryArchiver: create parent directories for symlinks #131

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -91,7 +91,9 @@ public void execute()
{
String dest = ( (SymlinkDestinationSupplier) resource ).getSymlinkDestination();
File target = new File( dest );
SymlinkUtils.createSymbolicLink( new File( fileName ), target );
File symlink = new File( fileName );
makeParentDirectories( symlink );
SymlinkUtils.createSymbolicLink( symlink, target );
}
else
{
Expand Down Expand Up @@ -142,15 +144,7 @@ protected void copyFile( final ArchiveEntry entry, final String vPath )

if ( !in.isDirectory() )
{
if ( !outFile.getParentFile().exists() )
{
// create the parent directory...
if ( !outFile.getParentFile().mkdirs() )
{
// Failure, unable to create specified directory for some unknown reason.
throw new ArchiverException( "Unable to create directory or parent directory of " + outFile );
}
}
makeParentDirectories( outFile );
ResourceUtils.copyFile( entry.getInputStream(), outFile );

setFileModes( entry, outFile, inLastModified );
Expand Down Expand Up @@ -187,6 +181,18 @@ public void run()

}

private static void makeParentDirectories( File file ) {
if ( !file.getParentFile().exists() )
{
// create the parent directory...
if ( !file.getParentFile().mkdirs() )
{
// Failure, unable to create specified directory for some unknown reason.
throw new ArchiverException( "Unable to create directory or parent directory of " + file );
}
}
}

private void setFileModes( ArchiveEntry entry, File outFile, long inLastModified )
{
if ( !isIgnorePermissions() )
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/codehaus/plexus/archiver/SymlinkTest.java
Expand Up @@ -102,6 +102,8 @@ public void testSymlinkDirArchiver()
final File archiveFile = new File( "target/output/dirarchiver-symlink" );
archiveFile.mkdirs();
archiver.setDestFile( archiveFile );
archiver.addSymlink("target/output/dirarchiver-symlink/aNewDir/symlink", ".");

archiver.createArchive();

File symbolicLink = new File( "target/output/dirarchiver-symlink/symR" );
Expand Down