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 3 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
@@ -0,0 +1,34 @@
package org.codehaus.plexus.archiver.dir;

import java.io.File;
import java.io.IOException;
import org.junit.Test;

public class DirectoryArchiverTest {

private static final File CURRENT_DIR = new File(".");
private static final File DEST_DIR = new File("target/output/testCreateDirsForSymlink");
private static final File SYMLINK_FILE = new File(DEST_DIR, "testSymlink");

/**
* Test case for ISSUE-130
* @throws IOException
*/
@Test
public void testSymlinkWithParentDirectory()
throws IOException
{
removeSymlink();
DirectoryArchiver archiver = new DirectoryArchiver();
archiver.addSymlink( SYMLINK_FILE.getPath(), CURRENT_DIR.getPath() );
archiver.setDestFile( CURRENT_DIR );
archiver.execute();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the tests. But there is already existing tests for symlinks for dir archivers (sorry forgot to mention it) - org.codehaus.plexus.archiver.SymlinkTest#testSymlinkDirArchiver. Maybe it would be better if this test is added there - to the same method or maybe a new method inside the same test class. I could help with it if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that, I didn't see the existing tests. That simplifies things.

removeSymlink();
}

private void removeSymlink()
{
SYMLINK_FILE.delete();
DEST_DIR.delete();
}
}