Skip to content

Commit

Permalink
#130 DirectoryArchiver: create parent directories for symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshans authored and plamentotev committed Feb 3, 2020
1 parent cc19267 commit 596257f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 596257f

Please sign in to comment.