Skip to content

Commit 596257f

Browse files
jameshansplamentotev
authored andcommitted
#130 DirectoryArchiver: create parent directories for symlinks
1 parent cc19267 commit 596257f

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/main/java/org/codehaus/plexus/archiver/dir/DirectoryArchiver.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ public void execute()
9191
{
9292
String dest = ( (SymlinkDestinationSupplier) resource ).getSymlinkDestination();
9393
File target = new File( dest );
94-
SymlinkUtils.createSymbolicLink( new File( fileName ), target );
94+
File symlink = new File( fileName );
95+
makeParentDirectories( symlink );
96+
SymlinkUtils.createSymbolicLink( symlink, target );
9597
}
9698
else
9799
{
@@ -142,15 +144,7 @@ protected void copyFile( final ArchiveEntry entry, final String vPath )
142144

143145
if ( !in.isDirectory() )
144146
{
145-
if ( !outFile.getParentFile().exists() )
146-
{
147-
// create the parent directory...
148-
if ( !outFile.getParentFile().mkdirs() )
149-
{
150-
// Failure, unable to create specified directory for some unknown reason.
151-
throw new ArchiverException( "Unable to create directory or parent directory of " + outFile );
152-
}
153-
}
147+
makeParentDirectories( outFile );
154148
ResourceUtils.copyFile( entry.getInputStream(), outFile );
155149

156150
setFileModes( entry, outFile, inLastModified );
@@ -187,6 +181,18 @@ public void run()
187181

188182
}
189183

184+
private static void makeParentDirectories( File file ) {
185+
if ( !file.getParentFile().exists() )
186+
{
187+
// create the parent directory...
188+
if ( !file.getParentFile().mkdirs() )
189+
{
190+
// Failure, unable to create specified directory for some unknown reason.
191+
throw new ArchiverException( "Unable to create directory or parent directory of " + file );
192+
}
193+
}
194+
}
195+
190196
private void setFileModes( ArchiveEntry entry, File outFile, long inLastModified )
191197
{
192198
if ( !isIgnorePermissions() )

src/test/java/org/codehaus/plexus/archiver/SymlinkTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ public void testSymlinkDirArchiver()
102102
final File archiveFile = new File( "target/output/dirarchiver-symlink" );
103103
archiveFile.mkdirs();
104104
archiver.setDestFile( archiveFile );
105+
archiver.addSymlink( "target/output/dirarchiver-symlink/aNewDir/symlink", "." );
106+
105107
archiver.createArchive();
106108

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

0 commit comments

Comments
 (0)