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

[SPARKL-166] Fix ZipUtil so zips created are readale in Windows #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cpk-core/src/pt/webdetails/cpk/utils/ZipUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class ZipUtil {
private String zipName;
private FileInputStream fis;
private FileName topFilename;
protected FileName topFilename;
ArrayList<String> fileListing = new ArrayList<String>();

protected Log logger = LogFactory.getLog( this.getClass() );
Expand Down Expand Up @@ -107,7 +107,8 @@ private ZipOutputStream writeEntriesToZip( Collection<FileObject> files, ZipOutp
logger.debug( "Files to process:" + files.size() );
logger.debug( "Files processed: " + i );
logger.debug( "Files remaining: " + ( files.size() - i ) );
logger.debug( file.getName().getPath() );
logger.debug( "Processing file: " + file.getName().getPath() );
logger.debug( "File path in zip: " + removeTopFilenamePathFromString( file.getName().getPath() ) );

fileListing.add( removeTopFilenamePathFromString( file.getName().getPath() ) );

Expand Down Expand Up @@ -229,10 +230,12 @@ private FileName getTopFileName( List<FileObject> files ) {
return topFileName;
}

private String removeTopFilenamePathFromString( String path ) {
protected String removeTopFilenamePathFromString( String path ) {

String filteredPath = null;
int index = this.topFilename.getParent().getPath().length();
//[SPARKL-166] Add +1 to the index so the filteredPath does not start with /. Starting with / makes
// the zip unreadable in the Windows zip utility.
int index = this.topFilename.getParent().getPath().length() + 1;
filteredPath = path.substring( index );


Expand Down
32 changes: 32 additions & 0 deletions cpk-core/test-src/pt/webdetails/cpk/utils/ZipUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package pt.webdetails.cpk.utils;


import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.pentaho.di.core.vfs.KettleVFS;
import org.pentaho.di.trans.steps.systemdata.SystemData;


/**
* Created by chrisdeptula on 2/20/16.
*/
public class ZipUtilTest {

private static ZipUtil zipUtil;

@Before
public void setUp() {
zipUtil = new ZipUtil();
}

@Test
public void testRemoveTopFilenamePathFromString() throws Exception {
String topFileName = "file:///pentaho/biserver/pentaho-solutions/system/sparkl/test.txt";
String fileName = "/pentaho/biserver/pentaho-solutions/system/sparkl/dashboards/admin/Main.cdfde";
zipUtil.topFilename = KettleVFS.getFileObject(topFileName).getParent().getName();
String removeTopFilename = zipUtil.removeTopFilenamePathFromString(fileName);
Assert.assertEquals( "sparkl/dashboards/admin/Main.cdfde", removeTopFilename );
}

}